1、直接在百度上输入IP
2、通过网页获取
2.1 万网获取本机公网IP: http://www.net.cn/static/customercare/yourip.asp
2.2 httpbin网站获取: https://httpbin.org/ip
2.3 其他地址汇总
https://cip.cc/
https://ipw.cn/ip/
https://ip.cn/
https://www.ip138.com/
https://myip.ipip.net/
https://ipchaxun.com/
https://ip.sb/
https://ipinfo.io/
http://txt.go.sohu.com/ip/soip
3、python程序获取本机公网IP
#!/usr/bin/env python
# -*- coding: utf8 -*-
from urllib import request
import re
# 通过sohu公共ip库获取本机公网ip
def get():
sohu_ip_url = 'http://txt.go.sohu.com/ip/soip'
r = request.urlopen(sohu_ip_url)
text = r.read().decode()
result = re.findall(r'\d+.\d+.\d+.\d+', text)
if result:
return result[0]
else:
return None
if __name__ == "__main__":
result = get()
print(result)
对于公网IP经常变换的情况,建议三种都用下,我在测试的时候,发现有的时候这三个获取的公网IP有时会不同。