RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
python访问你自己的公网ip地址的代码

把写内容过程中较好的一些内容片段记录起来,下面资料是关于python访问你自己的公网ip地址的内容,应该对小伙伴们有用途。

创新互联建站是一家专注于成都做网站、网站设计与策划设计,平乡网站建设哪家好?创新互联建站做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:平乡等地区。平乡做网站价格咨询:13518219792

import urllib,random,re

ip_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

网站栏目:python访问你自己的公网ip地址的代码
网站地址:http://scyingshan.cn/article/pghegs.html