通过API获取我的公共IP

时间:2010-06-22 22:22:45

标签: api ip

是否有来自某大公司的公共API来从程序中获取我的公共IP?

我找到了http://ip-address.domaintools.com/myip.xml,这正是我想要的,但遗憾的是它阻止了Python的urllib以及许多其他的http库,除非您欺骗用户代理(任何可以做的事情都可以'完全被称为API。

问题是我需要这些数据用于某些可能的开源库,因此我们必须遵守规则。我也知道我可以像print $_SERVER[REMOTE_ADDR]那样做,但我不想使用我的库为每个人提供流量。

那么,是否有类似上面的URL,但真正的API,允许机器人?

8 个答案:

答案 0 :(得分:92)

虽然不是大公司,但所有这些都应该有效:

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 :(得分:36)

您可以从我的服务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

提供更多详情

答案 2 :(得分:13)

以json格式提供更多详细信息,如latlong,country,city,user-agent:

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

https://www.trackip.net/ip

答案 3 :(得分:2)

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

$ curl ifconfig.me

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

$ echo `curl -s ifconfig.me`

答案 4 :(得分:1)

您可以使用Web服务API执行此操作,如:

see example of service: http://ip-api.com and usage: http://whatmyip.info
祝你好运!!!

答案 5 :(得分:0)

答案 6 :(得分:0)

是的,您可以尝试使用whoisthisip.com

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

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

答案 7 :(得分:0)

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

wget -qO- curlmyip.com
相关问题