python访问你自己的公网ip地址的代码
把写内容过程中较好的一些内容片段记录起来,下面资料是关于python访问你自己的公网ip地址的内容,应该对小伙伴们有用途。
import urllib,random,reip_regex = re.compile("(([0-9]{1,3}.){3}[0-9]{1,3})")def public_ip(): ''' Returns your public IP address. Output: The IP address in string format. None if not internet connection available. ''' # List of host which return the public IP address: for i in range(3): host = random.choice(hosts) try: results = ip_regex.findall(urllib.urlopen(host).read(200000)) if results: return results[0][0] except: pass # Let's try another host return None
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。