2010-06-22 108 views
67

有没有来自某个大公司的公开API来从程序中获取我的公共IP?通过API获取我的公共IP

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

问题是我需要这些数据用于某些潜在的开源库,所以我们必须按照规则来玩。我也知道我可以做像print $_SERVER[REMOTE_ADDR]那样的流利,但我不想将流量服务器传输给使用我的图书馆的所有人​​。

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

+0

相关:编程发现公网IP(http://stackoverflow.com/q/613471/4279) – jfs 2014-02-27 19:28:18

+0

鸭鸭围棋有一个确定你的IP地址的公开方法。我在这里详细说明了这个问题,因为这个问题已经关闭,我不能添加答案:http://stackoverflow.com/a/33743758/901641 – ArtOfWarfare 2015-11-16 20:11:40

+1

https://www.ipify.org/是一种替代服务。 – Horcrux7 2016-06-13 11:08:44

回答

87

虽然不是从大公司,这些都应该工作:

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 

来源

+1

太棒了!非常感谢,尤其是。为dyndns之一,那会做! – 2010-06-22 22:40:52

+3

icanhazip.com返回最干净的结果imho – mnagel 2013-07-10 11:50:29

+4

也http://ipinfo.io/ip – 2013-09-29 18:48:18

34

你可以得到你的IP,和一大堆其他信息,从我的服务http://ipinfo.io

$ 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

+1

不支持HTTPS – Navin 2013-12-10 20:28:44

+0

付费计划都支持HTTPS。请参阅http://ipinfo.io/pricing – 2014-01-19 20:46:10

2

我用这一个,易于请记住,它比其他人短:

$ curl ifconfig.me

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

$ echo `curl -s ifconfig.me`

+2

由于缓慢,我正在从_ifconfig.me_移动到_ipinfo.io_ – rodvlopes 2015-01-25 15:24:08

0

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

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

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

1

您可以使用Web服务的API里面做这项工作,如:

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

好运!

+0

http://ip-api.com/json是最快的方式,它具有最佳的响应时间。 150个请求/分钟 – ivahidmontazer 2017-08-29 10:40:01

0

如果你不能在你的系统变的wget安装卷曲将是:

wget -qO- curlmyip.com