python 3 获取本机公网ip的几种方法

参考博客:https://blog.csdn.net/conquerwave/article/details/77666226

from urllib.request import urlopen
from json import load my_ip = urlopen('http://ip.42.pl/raw').read()
print('ip.42.pl', my_ip) my_ip = load(urlopen('http://jsonip.com'))['ip']
print('jsonip.com', my_ip) my_ip = load(urlopen('http://httpbin.org/ip'))['origin']
print('httpbin.org', my_ip) my_ip = load(urlopen('https://api.ipify.org/?format=json'))['ip']
print('api.ipify.org', my_ip)

运行结果:

python 3 获取本机公网ip的几种方法


python 3 获取本机公网ip的几种方法

上一篇:Gradient Boosting Decision Tree学习


下一篇:笔记︱集成学习Ensemble Learning与树模型、Bagging 和 Boosting