import json,re
import urllib.request
def GetLocalIP():
IPInfo = urllib.request.urlopen("http://ip.chinaz.com/getip.aspx").read().decode('utf8') ##获取公网IP的网址
#return IPInfo ##读取所有信息
IP = re.findall(r"ip:'(.*?)',", IPInfo)[0] #正则配出单个Ip
return IP ###返回值
print(GetLocalIP()) ##打印输出