2010-06-22 107 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