通过sohu公共ip库获取本机公网ip

sohu 获取公网IP地址方式 http://txt.go.sohu.com/ip/soip

python方式

#!/usr/bin/python
# -*- coding:utf8 -*-

import urllib2
import re

url = urllib2.urlopen("http://txt.go.sohu.com/ip/soip")
text = url.read()
ip = re.findall(r'\d+.\d+.\d+.\d+',text)

print ip[0]

 

shell

echo  $(curl -s http://txt.go.sohu.com/ip/soip)|  grep -P -o -i "(\d+\.\d+.\d+.\d+)"
- THE END -
版权声明:
转载原创文章请注明,文章出处:http://kinggoo.com
原文地址:http://kinggoo.com/ob-ip.htm
发表评论?

3 条评论。

  1. 统计号码省份api
    https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=

    <?php
    
    
    function get_curl($url){
            //$headers['CLIENT-IP'] = '60.12.204.203';
            //$headers['X-FORWARDED-FOR'] = '60.12.204.203';
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
            //curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr );  //构造IP
            curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
            $result = curl_exec($ch);
            if(curl_errno($ch)){
                print_r(curl_error($ch));
            }
            curl_close($ch);
            return $result;
        }
        
        
    $url="https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=";
    $list_txt="tel.lis";
    $str=file_get_contents("$list_txt");
    $str=mb_convert_encoding($str, 'utf-8', 'GBK,UTF-8,ASCII');
    $arr=explode("\n",$str);
    
    
    foreach($arr as $row){//遍历每行
    $temp=explode(" ",$row);
        $url2=$url.$row;
        $getStr=get_curl($url2);
        
         error_log($getStr."tel:::".$url."\n", 3, "./hunan.list");
            
    }
    
  2. curl -s http://txt.go.sohu.com/ip/soip |grep -oP "(\d+\.){3}\d+"
  3. curl -s http://txt.go.sohu.com/ip/soip  | awk '{t=$0;gsub(/.*sohu_user_ip="|";.*/,"",t);print t}'

发表评论