获得通过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).
问题是,我需要这个数据,一些潜在的开源库,所以我们必须按规则玩。我也知道,我可以做像水木清华打印$ _ 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.
那么,有没有像上面的网址,但真正的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屋!