新聞中心
把寫內(nèi)容過程中較好的一些內(nèi)容片段記錄起來,下面資料是關(guān)于python訪問你自己的公網(wǎng)ip地址的內(nèi)容,應(yīng)該對小伙伴們有用途。
創(chuàng)新互聯(lián)建站是一家專注于成都做網(wǎng)站、網(wǎng)站設(shè)計與策劃設(shè)計,平鄉(xiāng)網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)十余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:平鄉(xiāng)等地區(qū)。平鄉(xiāng)做網(wǎng)站價格咨詢: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
網(wǎng)頁標(biāo)題:python訪問你自己的公網(wǎng)ip地址的代碼
鏈接地址:http://biofuelwatch.net/article/pghegs.html