[英]What API, package or library is easiest to find the location of an IP address?
這是我的情景。 我希望能夠用python編寫腳本,當輸入IP地址時,它將在API上查找該IP地址,並返回結果。 任何人都可以告訴我一個良好的工作查找API與代碼。 例如,這是hostip:
import urllib
response = urllib.urlopen('http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true').read()
print(response)
但是hostIP有一個非常小的數據庫,並且不能返回許多位置。
我在freegeoip.net上取得了巨大的成功。 它們提供公共(免費)API,或者您可以在自己的服務器上運行它。
簡單的代碼示例:
import urllib
response = urllib.urlopen('http://freegeoip.net/json/1.2.3.4').read()
print(response)
你可以看看userinfo.io 。
發布GET http://api.userinfo.io/userinfos
將返回您要求的所有信息。 您還可以在參數中指定IP地址: GET http://api.userinfo.io/userinfos?ip_address=888.888.888.888
。
響應如下所示:
{
request_date: "2014-09-18T04:11:25.154Z",
ip_address: "192.77.237.95",
position: {
latitude: 37.7758,
longitude: -122.4128,
accuracy: 3 // This is the accuracy radius, in kilometers
},
continent: {
name: "North America",
code: "NA",
},
country: {
name: "United States",
code: "US",
},
city: {
name: "San Francisco",
code: "94103"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.