• perl 读取cookie


    use  LWP::UserAgent;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    use Net::Ping;  
    use Socket;
    use Net::SMTP;
    use LWP;
    use LWP::Simple;
    use LWP::UserAgent;
    use HTTP::Cookies;
    use HTTP::Headers;
    use HTTP::Response;
    use Encode;
    use URI::Escape;
    use URI::URL;
    use File::Temp qw/tempfile/;
    my $ua = LWP::UserAgent->new;
    $ua->timeout(5);
    $ua->env_proxy;
    $ua->agent("Mozilla/8.0");
    my $cookie_jar = HTTP::Cookies->new(
                                       file=>'lwp_cookies.txt',
                                       autosave=>1,
                                       ignore_discard=>1
                                       );
    $ua->cookie_jar($cookie_jar);
    my $login_url = 'http://192.168.32.83/zabbix/index.php';
    my $res = $ua->post($login_url,{
    	                  'autologin'=>'1',
                              'enter'=>'Sign in',
    			  'name'=>'admin',
                              'password'=>'zabbix'
                                   },
                               'User-Agent'=>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0',
                               'Host'=>'192.168.32.83',
                               'Referer'=>'http://192.168.32.83/zabbix/'
                               );
    
                my $content = $res->content();
                print $res->status_line . "
    ";
                print $res->as_string();              
                print $res->content();
                
                open (LOG ,"<","/home/scan/lwp_cookies.txt");  
                        while (<LOG>) {  
                        chomp; 
                         $sid=$1   if ($_ =~ /.*zbx_sessionid=(.*?);.*/)
                                     };
                  
    
                 print $sid."
    ";;       
                 
                 $cookie_jar->scan(sub {
                      my ($k,$v)=@_[1,2];
                      if ($k eq 'zbx_sessionid'){
                             $sid=$v;
                               };
                          });
                 print $sid."
    ";
    
    [root@dr-mysql01 ~]# perl zz.pl 
    302 Found
    HTTP/1.1 302 Found
    Connection: close
    Date: Fri, 15 Jul 2016 02:04:10 GMT
    Location: tr_status.php
    Server: Apache/2.2.15 (CentOS)
    Content-Length: 0
    Content-Type: text/html; charset=UTF-8
    Client-Date: Fri, 15 Jul 2016 02:11:26 GMT
    Client-Peer: 192.168.32.83:80
    Client-Response-Num: 1
    Set-Cookie: zbx_sessionid=e9365512c43faa607f76c9306f979cfc; expires=Mon, 15-Aug-2016 02:04:10 GMT
    Set-Cookie: zbx_sessionid=99142dca7311038e6d335d32060b5ef3; expires=Mon, 15-Aug-2016 02:04:10 GMT
    X-Powered-By: PHP/5.3.3
    
    e9365512c43faa607f76c9306f979cfc
    99142dca7311038e6d335d32060b5ef3
    [root@dr-mysql01 ~]# cat lwp_cookies.txt
    #LWP-Cookies-1.0
    Set-Cookie3: zbx_sessionid=99142dca7311038e6d335d32060b5ef3; path="/zabbix"; domain=192.168.32.83; expires="2016-08-15 02:04:10Z"; version=0
    

  • 相关阅读:
    【转】Windows Server 2003为什么识别不了的移动硬盘
    VBSCRIPT常用函数【转】
    【轉】javascript实现图片缩略与优化
    【转】Tips:禁用Windows Beep声
    EXT同struts2后台交互一个中文问题
    ASCII码对照表[转]
    bat判断进程存在不存在
    look与look like
    美国俚语there was no snap in his turtle
    take credit for用法
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350529.html
Copyright © 2020-2023  润新知