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
评论列表
文章目录