python获取到本机的公网IP

5行代码获取到本机的公网IP

from urllib.request import urlopen
import re
text = str(urlopen("http://txt.go.sohu.com/ip/soip").read())
ip = re.findall(r'\d+.\d+.\d+.\d+',text)
print(ip[0])
posted @ 2021-03-05 16:59  pythonliuwei  阅读(250)  评论(0编辑  收藏  举报