Perl 调阿狸 IP接口
发布时间:2020-12-15 23:46:25 所属栏目:大数据 来源:网络整理
导读: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 $_n";$host = "http://ip.taobao.com/service/getIpInfo.php?ip=$_";$content = get($host);$conte
<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 $_n"; $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 "okn"}else {print "errn"}; if ($content =~ /浙江/){if ($content =~ /联通/){ open (B,">>129-联通.log"); print B ("$contenn"); print "$contentn";}}; if ($content =~ /浙江/){if ($content =~ /电信/){ open (C,">>129-电信.log"); print C ("$contenn"); print "$contentn";}}; }; v-lhb-app01:/home/tomcat> cat s2.pl use Encode; use Encode::CN; use JSON; use URI::Escape; use LWP::Simple; print "hostip is $_n"; $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",$content); print "$content is $contentn"; 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"}} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |