获取公网IP
1 import requests 2 import re 3 res = requests.get("https://myip.ipip.net",timeout=5).text 4 ip = re.findall(r'(\d+\.\d+\.\d+\.\d+)', res)[0] 5 print(ip)
获取局域网IP
1 import socket 2 3 res = socket.gethostbyname(socket.gethostname()) 4 print(res)
标签:res,socket,python,IP,局域网,公网,import,本机 From: https://www.cnblogs.com/Grouth-Diary/p/17611397.html