有没有办法用Python检查我的公网IP地址?我在家里有一个Cloudflare和VPS的帐户(但是动态IP)。我需要更新VPN的IP之前,有一个帐户的OVH和DDNS工作后,迁移不工作。
发布于 2020-04-26 03:26:25
请求:
import requests
response = requests.get('http://ifconfig.me')
print(response.text)
python 2:
import urllib2
response = urllib2.urlopen('http://ifconfig.me')
print response.read()
python 3:
from urllib import request
response = request.urlopen('http://ifconfig.me')
print(response.read())
发布于 2020-04-26 03:39:12
有很多网站提供了简单的API来检查你连接的IP地址。
举个例子:
➜ ~ curl 'https://api.ipify.org?format=json'
{"ip":"1.2.3.4"}
您可以使用python库(如Requests)在python代码中调用接口。
# download requests with `pip install requests`
import requests
res = requests.get("https://api.ipify.org?format=json")
your_ip = res.json() # {"ip" : "1.2.3.4"}
发布于 2020-10-12 14:27:33
最近,我创建了一个简单的docker镜像,它可以让您的本地ip与Cloudflare保持同步,也就是Cloudflare动态域名(DDNS)。请在此处查看:https://github.com/marcelowa/cloudflare-dynamic-dns
https://stackoverflow.com/questions/61431225
复制相似问题