通过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 -
版权声明:
转载原创文章请注明,文章出处://kinggoo.com
原文地址:https://kinggoo.com/ob-ip.htm
发表评论?

3 条评论。

  1. curl -s http://txt.go.sohu.com/ip/soip |grep -oP "(\d+\.){3}\d+"
  2. curl -s http://txt.go.sohu.com/ip/soip  | awk '{t=$0;gsub(/.*sohu_user_ip="|";.*/,"",t);print t}'

发表评论


此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据