通过API获取我的公共IP

Sla*_*a V 74 api ip

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

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

问题是我需要这些数据用于一些潜在的开源库,所以我们必须遵守规则.我也知道我可以做类似的事情print $_SERVER[REMOTE_ADDR],但我不想使用我的库为所有人提供流量服务.

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

Jam*_*ong 95

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

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
Run Code Online (Sandbox Code Playgroud)

资源

  • 还有http://ipinfo.io/ip (4认同)
  • 您可以查看https://www.ipify.org/,它具有明确的API并支持HTTPS. (4认同)
  • icanhazip.com返回最干净的结果imho (3认同)

Ben*_*ing 38

您可以从我的服务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
}
Run Code Online (Sandbox Code Playgroud)

如果你只想要IP:

$ curl ipinfo.io/ip
67.188.232.131
Run Code Online (Sandbox Code Playgroud)

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

$ curl ipinfo.io/org
AS7922 Comcast Cable Communications, Inc.
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请访问http://ipinfo.io/developers

  • 不支持HTTPS (2认同)

nba*_*ari 14

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

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

要么

https://www.trackip.net/ip