通过 API 获取我的公共 IP [英] Getting my public IP via API
问题描述
是否有一些大公司的公共 API 可以从程序中获取我的公共 ip?
Is there a public API from some big company to get my public ip from within a program?
我找到了 http://ip-address.domaintools.com/myip.xml
,这正是我想要的,但不幸的是它阻止了 Python 的 urllib
以及许多其他 http 库,除非您欺骗用户代理(任何这样做都不能称为 API).
I've found http://ip-address.domaintools.com/myip.xml
, which is exactly what I want, but unfortunately it blocks Python's urllib
as well as many other http libraries, unless you spoof user-agent (anything doing that can't be called an API at all).
问题是我需要这些数据用于一些潜在的开源库,所以我们必须遵守规则.我也知道我可以像 print $_SERVER[REMOTE_ADDR]
那样做一些事情,但我不想为使用我的库的每个人提供流量.
The problem is that I need this data for some potentially open source library, so we have to play by the rules. I also know that I can just do smth like print $_SERVER[REMOTE_ADDR]
, but I don't want to server traffic to everyone using my library.
那么,是否有类似上面的 URL 的东西,但真正的 API,允许机器人?
So, is there something like the URL above, but real API, that allows robots?
推荐答案
虽然不是来自大公司,但所有这些都应该有效:
While not from big companies, all of these should work:
curl icanhazip.com
curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g'
host -t a dartsclink.com | sed 's/.*has address //'
curl curlmyip.com
curl ifconfig.me # this has a lot of different alternatives too, such as ifconfig.me/host
来源
这篇关于通过 API 获取我的公共 IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!