Python 哪种API、包或库最容易找到IP地址的位置?
这是我的设想。我希望能够用python编写一个脚本,当输入IP地址时,它会在API上查找该IP地址,并返回结果。谁能告诉我一个很好的代码查找API。例如,这是hostip:Python 哪种API、包或库最容易找到IP地址的位置?,python,geolocation,ip-geolocation,Python,Geolocation,Ip Geolocation,这是我的设想。我希望能够用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的数据库非常小,无法返回许多位
import urllib
response = urllib.urlopen('http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true').read()
print(response)
但是,hostIP的数据库非常小,无法返回许多位置。我在这方面取得了巨大成功。它们提供了一个公共(免费)API,或者您可以在自己的服务器上运行它 简单代码示例:
import urllib
response = urllib.urlopen('http://freegeoip.net/json/1.2.3.4').read()
print(response)
你可以看看
发出GET命令http://api.userinfo.io/userinfos
将返回您需要的所有信息。您还可以在参数中指定IP地址:GEThttp://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"
}
}
可能是离题了!多谢了。完美简单的答案。python 4.3.2中的urllib请求是什么?应该提供Python 3中所需的内容