def public_ip(self):
ip_regex = re.compile("(([0-9]{1,3}\.){3}[0-9]{1,3})")
# List of host which return the public IP address:
hosts = """http://www.lawrencegoetz.com/programs/ipinfo/
http://mwburden.com/cgi-bin/getipaddr
http://checkip.eurodyndns.org/
http://checkip.dyndns.org/
http://checkrealip.com/
http://adresseip.com
http://www.ipchicken.com/
http://checkmyip.com/
http://www.naumann-net.org/""".split("\n")
for i in hosts:
host = i.strip()
#print(host)
try:
response = request.urlopen(host).read()
result = ip_regex.findall(response.decode('utf-8'))
if result:
return result[0][0]
except:
pass
return "UNKNOWN"
评论列表
文章目录