最近在用java寫網絡聊天室
想跨局域網訪問別的電腦 那就需要他的外網IP
每次都要使用瀏覽器來獲取外網IP
然后就像這用python的爬蟲寫了一個獲取外網IP 的小程序
#作用:獲取本地的外網出口地址
import requests
import re
def getIP():
headers = {}
headers['User-Agent'] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"
response = requests.get('http://www.baidu.com/s?wd=ip',headers=headers)
html = response.text
reGET = re.compile('fk="(.*?)"').findall(html)
for i in reGET:
print('外網地址: %s'%i)
getIP()
執行結果:
這個是本人自己的一個小想法;大佬勿噴!!!