Python中如何获取只返回请求IP地址信息的干净网站?
之前用过一个返回请求的 ip 地址信息 的网站, 很干净, 只是一个 json(或者文本). 忘记了, 有没有人知道啊 我记得域名中 有 tool 这个单词.
Python中如何获取只返回请求IP地址信息的干净网站?
curl 'https://api.ipify.org?format=json’
其实你拿 myip + json 这个关键字在谷歌里一搜就有了,大兄弟
我理解你想找一个能直接返回请求者IP地址的网站,而不是返回一堆HTML、广告或其他无关信息的页面。
最常用且稳定的就是 httpbin.org,它专门用于HTTP测试。获取IP地址的端点非常干净:
import requests
def get_my_ip():
try:
# 这个端点只返回你的公网IP地址
response = requests.get('https://httpbin.org/ip', timeout=5)
response.raise_for_status() # 检查HTTP错误
ip_data = response.json()
return ip_data['origin']
except requests.exceptions.RequestException as e:
print(f"请求失败: {e}")
return None
except (KeyError, ValueError) as e:
print(f"解析响应失败: {e}")
return None
# 使用示例
my_ip = get_my_ip()
if my_ip:
print(f"你的IP地址是: {my_ip}")
运行这段代码,你会得到类似 "203.0.113.1" 这样的纯IP地址字符串。httpbin.org/ip 端点返回的是干净的JSON格式,只包含IP信息,没有多余内容。
如果你想要更简单的纯文本响应,可以用 icanhazip.com:
import requests
response = requests.get('https://icanhazip.com')
print(response.text.strip()) # 直接输出IP地址,没有JSON包装
这两个服务都很可靠,httpbin.org 更适合程序化处理(JSON格式),icanhazip.com 则更简洁(纯文本)。
总结:用 httpbin.org/ip 获取干净的结构化IP数据。
curl ip.sb
三年前的帖子: /t/276129?p=1 里面提到很多,而且三年了还可以验证一波稳定性
http://icanhazip.com/
这个满足你的需求
自己写一个嘛,😄
我用的这个 curl <a target="_blank" href="https://ip.cn" rel="nofollow noopener">https://ip.cn</a> , 这东西还能反查 IP curl <a target="_blank" href="https://ip.cn/114.114.114.114" rel="nofollow noopener">https://ip.cn/114.114.114.114</a>
我假装认为你的头像并不是针对我.
curl myip.ipip.net
多谢 之前就是 httpbin 这个
谢谢各位
实在太懒了
如果只是要纯文本的话
dig +short myip.opendns.com .opendns.com
https://api.ipdata.co/?api-key=test
如果考虑到国际使用也可以用这个
一楼二楼两位老哥推荐的我上海移动直连打不开,不知是哪一级的墙给挡住了
我自己博客上弄的,自用的,还算稳定
https://lerry.me/ip
还有 ua
https://lerry.me/ua
离题回答一个,可能很多人不知道:
https://www.v2ex.com/ip
#9 ip.cn 挂了好长时间了
这个不错,GET 只返回文本,连 html 都省了。
curl ip.sb
curl xabc.io/p
自建的 API: https://api.tcotp.cn:4443/
提供了多种接口,多种返回类型
??? 我头像?
httpbin.org 可以获取各类信息,包括 IP 地址。
虽然不是楼主所说的网站,但是我觉得 ipip.net 很好用,主要是数据很准确,好像也有 API
还有个获取 IP 的: https://api.akkariin.com:24443/getip/
推荐下我自己的网站 https://api.nettool.app/ip
curl myip.ipip.net
curl httpbin.org/ip
这不巧了吗这不是…
没有没有,我这个头像是提醒自己的。
自己做个就行了
#9 经常用curl <a target="_blank" href="http://ip.cn/example.com" rel="nofollow noopener">ip.cn/example.com</a> -L curl <a target="_blank" href="http://ip.cn/1.1.1.1" rel="nofollow noopener">ip.cn/1.1.1.1</a> -L,目前没有找到替代的 其他的都只能查 ip, 但是 ip.cn 的地址库不是很准确,还是需要 web 查一查, 另外命令行的工具强制 https 对 curl 不好啊…
安利一下自制的命令行查 IP 小工具 https://github.com/Jamesits/myip
curl ip.sb


