通过API获取我的公共IP

是否有一个大公司的公共API来获取我的公共IP在程序中?

我find了http://ip-address.domaintools.com/myip.xml ,这正是我想要的,但不幸的是,它阻止了Python的urllib以及许多其他的http库,除非你欺骗用户代理(任何事情根本不能被称为API)。

问题在于我需要这些数据用于某些潜在的开源库,所以我们必须遵守规则。 我也知道,我可以做print $_SERVER[REMOTE_ADDR] ,但我不希望服务器stream量使用我的图书馆的每个人。

那么,有没有像上面的URL,但真正的API,允许机器人?

虽然不是来自大公司,但所有这些都应该工作:

 curl icanhazip.com curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g' host -ta 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 

资源

您可以从我的服务http://ipinfo.io获取您的IP以及大量其他信息:;

 $ curl ipinfo.io { "ip": "67.188.232.131", "hostname": "c-67-188-232-131.hsd1.ca.comcast.net", "city": "Mountain View", "region": "California", "country": "US", "loc": "37.385999999999996,-122.0838", "org": "AS7922 Comcast Cable Communications, Inc.", "phone": 650 } 

如果你只想要IP:

 $ curl ipinfo.io/ip 67.188.232.131 

这也适用于其他领域,例如:

 $ curl ipinfo.io/org AS7922 Comcast Cable Communications, Inc. 

更多详细信息可在http://ipinfo.io/developers

在json格式中给出像latlong,国家,城市,用户代理更多的细节:

https://www.trackip.net/ip?json

要么

https://www.trackip.net/ip

我用这个,容易记住,比其他人短:

$ curl ifconfig.me

PROTIP:请记住,如果在shell脚本中使用curl,则必须使用-s选项,否则将打印下载进度表。

$ echo `curl -s ifconfig.me`

您可以使用这样做的Web服务API:

 see example of service: http://ip-api.com and usage: http://whatmyip.info 

祝你好运!!!

是的,你可以尝试与whoisthisip.com

http://whoisthisip.com/HRAS/注册whoisthisip.com获取一个网站的IP地址信息,如城市位置,国家的位置和域名。;

login后,您将获得一个参考码和一个url,以查看和获取您注册网站的IP地址信息。

如果你不能在你的系统中安装curl,那么wget变体将是:

 wget -qO- curlmyip.com