Perl 调阿狸 IP接口

<pre name="code" class="sql">use Encode;
use Encode::CN;
use JSON; 
use URI::Escape;
use LWP::Simple;
open (LOG ,"<","129_1");
while (<LOG>){
print "hostip is $_
";	
$host = "http://ip.taobao.com/service/getIpInfo.php?ip=$_";
$content = get($host);
$content =~ s/\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;  
$content=encode(gbk,$content);
if ($content =~ /^{"code":0/){
   print "ok
"}else
   {print "err
"};
if ($content =~ /浙江/){if ($content =~ /联通/){
   open (B ,">>129-联通.log");
    print B ("$conten
");
   print "$content
";}};

if ($content =~ /浙江/){if ($content =~ /电信/){
      open (C ,">>129-电信.log");
    print C ("$conten
");
   print "$content
";}};
};


v-lhb-app01:/home/tomcat> cat s2.pl 
use Encode;
use Encode::CN;
use JSON; 
use URI::Escape;
use LWP::Simple;
print "hostip is $_
";	
$host = "http://ip.taobao.com/service/getIpInfo.php?ip=202.101.172.35";
$content = get($host);
$content =~ s/\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;  
$content=encode(gbk,$content);
print "$content is $content
";
v-lhb-app01:/home/tomcat> perl s2.pl 
hostip is 
$content is {"code":0,"data":{"country":"中国","country_id":"CN","area":"华东","area_id":"300000","region":"浙江省","region_id":"330000","city":"杭州市","city_id":"330100","county":"","county_id":"-1","isp":"电信","isp_id":"100017","ip":"202.101.172.35"}}



                                    
原文地址:https://www.cnblogs.com/hzcya1995/p/13351807.html