当我在 Google 上搜索 IP 地址时,会返回许多结果,其中一些会告诉不同城市的 IP 地址。
如何从 IP 地址中找到位置?
The reason you are getting different results is that there are different geolocation databases. Each of them returns a different result. In fact, there are studies to the reliability of these geolocation databases (e.g. http://www.caida.org/publications/papers/2011/geocompare-tr/).
In my experience, this one is pretty reliable:
You should compare multiple databases and figure out which is the most probable location yourself.
公平地说,您必须考虑到用户可能在代理服务器后面。
一般术语是地理 IP 查找或地理 IP。了解这一点的最佳方法是拥有一个与区域相关的 IP 地址的最新数据库。
可下载:
免费下载数据库 (~25mb)
http://dev.maxmind.com/geoip/legacy/geolite/
在线的:
geobytes.com/IpLocator.htm?GetLocation
www.ipligence.com/geolocation
这是 Ruby 中的一个模块:http: //www.chipstips.com/? p=524
注意:这是非常不准确的,并且基于已发布的表格可能无法保持准确。
它不准确的原因之一是因为 NAT 后面的任何 IP 都会报告最外层 NAT 网关的位置。因此,它通常在您的 ISP 甚至之外。
查看http://www.iplocation.net/ ,其中列出了 4 个用于将 IP 映射到地理位置的地理位置提供程序。
该链接还链接到由 James A. Muir 撰写的名为“Internet Geolocation and Evasion”的文档http://www.ccsl.carleton.ca/~jamuir/papers/TR-06-05.pdf 。在文档中,Muir 确定了 9 种方法及其局限性,以获取用户的地理位置数据。
You can use some API service for that.
For example, https://apiip.net , their API provides a lot of info about the IP, also you can request XML responses if needed.
Simple GET call:
https://apiip.net/api/check?ip=67.250.186.196&accessKey={your_api_key}
Response:
{
"ip": "67.250.186.196",
"continentCode": "NA",
"continentName": "North America",
"countryCode": "US",
"countryName": "United States",
"countryNameNative": "United States",
"city": "New York",
"postalCode": "10001",
"latitude": 40.8271,
"longitude": -73.9359,
"capital": "Washington D.C.",
"phoneCode": "1",
"countryFlagEmoj": "",
"countryFlagEmojUnicode": "U+1F1FA U+1F1F8",
"isEu": false,
"languages": {
"en": {
"code": "en",
"name": "English",
"native": "English"
}
},
"currency": {
"code": "USD",
"name": "US Dollar",
"symbol": "$",
"number": "840"
},
"timeZone": {
"id": "America/New_York",
"currentTime": "10/26/2021, 2:54:10 PM",
"code": "EDT",
"timeZoneName": "EDT",
"utcOffset": -14400
},
"connection": {
"asn": 12271,
"isp": "Charter Communications Inc"
},
"security": {
"isPublicProxy": false,
"isResidentialProxy": false,
"isTorExitNode": false,
"network": "67.250.176.0/20"
}
}
IPInfoDB is one that works and offers a free RESTful API, with libraries for several languages including Python, Ruby and PHP.