common.py 文件源码

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

项目:brush 作者: chenshiyang2015 项目源码 文件源码
def get_local_ip(ip):
    try:
        proxy_support = urllib2.ProxyHandler({'http': 'http://' + ip})
        opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
        urllib2.install_opener(opener)
        request = urllib2.Request('http://ip.chinaz.com/getip.aspx')
        # request.add_header("cookie", env.COOKIE)
        request.add_header("User-Agent", getUA())
        fp = urllib2.urlopen(request)
        mybytes = fp.read()
        # note that Python3 does not read the html code as string
        # but as html code bytearray, convert to string with
        mystr = mybytes.decode('utf-8')
        fp.close()
        ip = mystr.find("ip")
        add = mystr.find("address")
        ip = mystr[ip + 4:add - 2]
        address = mystr[add + 9:-2]
        return [ip, address]

    except (HTTPError, URLError, Exception) as e:
        log.step_warning ('??ip????---> %s' % e)
        return [ip, 'address']

    # ??????????random.randint(0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号