RpiState.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Rpi-envMonitor 作者: conanwhf 项目源码 文件源码
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"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号