这是我的场景。我希望能够用python编写一个脚本,当输入IP地址时,它会在API上查找ip地址,并返回结果。有人能告诉我一个良好的工作查找API的代码。例如,这是软管:
import urllib
response = urllib.urlopen('http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true').read()
print(response)然而,hostIP有一个非常小的数据库,不能返回许多位置。
发布于 2015-02-10 18:52:29
我在freegeoip.net上取得了巨大的成功。它们提供公共(免费) API,或者您可以在自己的服务器上运行它。
简单代码示例:
import urllib
response = urllib.urlopen('http://freegeoip.net/json/1.2.3.4').read()
print(response)发布于 2015-02-12 16:52:39
你可以看看userinfo.io。
发出一个GET http://api.userinfo.io/userinfos将返回您所要求的所有信息。还可以在参数:GET http://api.userinfo.io/userinfos?ip_address=888.888.888.888中指定IP地址。
答复看起来是这样的:
{
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"
}
}https://stackoverflow.com/questions/28439373
复制相似问题