zoukankan      html  css  js  c++  java
  • 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"}}


    
                                        
    
  • 相关阅读:
    09-JS的事件流的概念(重点)
    08-jQuery的位置信息
    07-小米导航案例
    python-selector模块
    python--day9--异步IO、数据库、队列、缓存
    python--select多路复用socket
    python--gevent高并发socket
    python--协程
    python--进程锁、进程池
    python--多进程
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351807.html
Copyright © 2011-2022 走看看