sync_jrw.pl

use Encode;
use LWP::UserAgent;
use HTTP::Cookies;;
$cookie_jar = HTTP::Cookies->new(
file=>'d:\tmp\1.cookie',
autosave=>1
);

my $url = 'http://137.0.10.21:1407/aniam/resDeviceSD/toResDeviceSrch?devTypeId=7';
my $post_url = 'http://137.0.10.21:1407//aniam/resDeviceSD/getResDeviceList';
my $url = 'http://137.0.10.21:1407/aniam/index.jsp';

my %headers=('Accept'=>'/',
'Accept-Language'=>'zh-cn',
'User-Agent'=>'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)',
'Accept-Charset' => 'gbk,iso-8859-1,*,utf-8');
#my $response = $ua->get($url,%headers);
my $ua  = LWP::UserAgent->new;
$ua->cookie_jar($cookie_jar);

my $response = $ua->get($url);
$ck = '';
if($response->is_success){
 open WH,'>t3.html';
 print $ua->cookie_jar()->as_string();
 $ckt = $ua->cookie_jar()->as_string();
 $ck = ($ckt =~ /JSESSIONID=(.*?);/?$1:0);
 print $ck;
 print WH $response->content;
 close WH;
}else{
# print 'Error!';
 print $response->content;
}
#capture
#$ua->default_header('JSESSIONID'=>$ck);
my $url = 'http://137.0.10.21:1407/aniam/captcha/getCaptchaImage';
my $response = $ua->get($url);
if($response->is_success){
 open WH,'>t3.jpg';
 binmode(WH);
 print WH $response->content;
 close WH;
}else{
# print 'Error!';
 print $response->content;
}
print "Enter the Capture:";
`start t3.jpg`;
$kapture = <STDIN>;
chomp $kapture;

$url_check_capture = 'http://137.0.10.21:1407/aniam/captcha/checkCaptchaCode';
$response = $ua->post( $url_check_capture ,["value"=> "$kapture"]);
if($response->is_success){
 print $response->content;
}else{
 print "post_check_captureError!\n";
# print $response->content;
}

$url_get = 'http://137.0.25.140:18001/ccatstep/UserAction.do?method=login&userid={null}&passWord=l{null}&callback=jQuery1620019147698135514202_1445593100734&_=1445593122296';
my $response = $ua->get($url);
if($response->is_success){
 #print $response->content;
 print "get__capture!\n";
}else{
 print "get__captureError!\n";
 #print $response->content;
}

$url_check_j= 'http://137.0.10.21:1407/aniam/j_spring_security_check';
$response = $ua->post( $url_check_j,["kaptcha"=> "$kapture","j_username"=>'SD-LY@!%#{null}','j_password'=>'{null}']);
if($response->is_success){
 print $response->content;
}else{
 print "post__jError!\n";
 #print $response->content;
}
print $ua->cookie_jar()."\n";

$url = 'http://137.0.10.21:1407/aniam/resDeviceSDBaf/getResDeviceBafList';
%params = (
 "areaId" => "",
 "devTypeId" => "",
 "devSubTypeId" => "",
 "devName" => "",
 "ipAddress" => "10.45.23.244",
 "pingStatus" => "",
 "snmpStatus" => "",
 "retFlag" => "true",
 "pageNumber" => "1",
 "maxResultsPerPage" => "80",

);

@ips  = ('10.44.10.76','10.44.5.45');
$in = $ARGV[0];
open RH,$in or die "$!";
@ips  = <RH>;chomp @ips ;
close RH;
open WH,">jieru_dev.txt";
for($pN = 0; $pN < @ips; $pN ++){
$params{'ipAddress'} = $ips[$pN];
$response = $ua->post($url,[%params]);


if($response->is_success){
 $ln = $response->content;
# print WH $ln;
$tag = 0;
while($ln =~ /ipAddress=(.*?)\&/isg){
 if($1 ne $params{'ipAddress'}){
  next;
 }else{
  #print $params{'ipAddress'}."\t同步正常\n";
  $tag ++;
  next;
 }
# if($ln =~ /ipAddress=(.*?)\&/){
#  print $params{'ipAddress'}."\t".$1."\t同步正常\n";
# }else{
#  print $params{'ipAddress'}."\t".$1."\t未同步\n";
# }
}
$tag = $tag / 2;
if($tag == 0 ){

 print $params{'ipAddress'}."\t未同步\n";
}elsif($tag == 1 ){
 print $params{'ipAddress'}."\t同步正常\n";
}elsif($tag > 2 ){
 print $params{'ipAddress'}."\t同步异常\t$tag个设备\n";
}
 #print WH $ln;
}else{
 print "post_check_captureError!\n";
}
}
close WH;

你可能感兴趣的:(sync_jrw.pl)