IP地址的位置检测技术有哪些?
我知道要看
$_SERVER['HTTP_ACCEPT_LANGUAGE']
(不准确,但对于检测位置最有用,例如,如果某个 IP 范围的用户将其浏览器设置为法语,则意味着该范围)属于法国
和
gethostbyaddr($_SERVER['REMOTE_ADDR'])
(查看国家/地区代码顶级域名)
那么可能是 whois gethostbyaddr($_SERVER['REMOTE_ADDR'])
有时:
$HTTP_USER_AGENT
(Firefox 的用户代理字符串有语言代码,不准确,但主要可用于检测位置)
我也知道如何获取时区,但它在新版本中不起作用浏览器。
此外,还有 CSS 问题检测访问者的历史记录,它可以用来查看他/她访问过哪些谷歌和维基百科页面(google.co.uk、google.com.tr)
但是城市呢?
What are the location detecting techniques for IP addresses?
I know to look at the
$_SERVER['HTTP_ACCEPT_LANGUAGE']
(not accurate but mostly useful to detect location, for example if an IP range's users set French to their browser then it means that this range) belongs to France
and
gethostbyaddr($_SERVER['REMOTE_ADDR'])
(to look country code top-level domain)
then may be to whois gethostbyaddr($_SERVER['REMOTE_ADDR'])
sometimes:
$HTTP_USER_AGENT
(Firefox's user agent string has language code, not accurate but mostly can be used to detect the location)
Also I know how to get the time zone but it does not work in the new browsers.
Moreover there is css issue that detects visitor's history, it can be used to see what google and wikipedia pages he/she has visited (google.co.uk, google.com.tr)
But what about cities?
发布评论
评论(8)
如果没有将 IP 地址映射到城市/国家/提供商的数据库,您就无法做到这一点。您可以使用一些商业产品,例如 ip2location。
据我所知,没有免费的替代方案,因为维护这样的 IP 数据库需要大量工作。免费替代方案:GeoIP2更新:
如果您投入足够的时间,有几件事可以让您创建这样的数据库:
如果您进行反向 DNS 查找,甚至可以读取纯文本形式的城市名称。有时是
更加神秘。例如我目前有 p5dcf6c4a.dip.t-dialin.net ,并且我没有
命名方案的想法是..
其上行链路的位置
You can't do this without a database that maps IP addresses to cities/countries/providers. There are commercial offerings such as ip2location that you could use.
AFAIK there is no free alternative though, as maintaining such a IP database is quite a lot of work.Free alternative: GeoIP2Update:
There are several things that allow you to create such a db, if you invest enough time:
even read the city name in plain text if you do a reverse-DNS lookup. Sometimes it is
more cryptic. For example I currently have p5dcf6c4a.dip.t-dialin.net , and I have no
idea that the naming scheme is..
the location of its uplink
如果您正在寻找一些复制粘贴解决方案,我发现了这段代码:
希望这对某人有帮助。
If you looking for some copy - paste solution, i foudn this code :
Hope this helps somebody.
您可以使用数据库或 API(托管数据库)将 IP 地址映射到其位置(城市、国家、邮政编码)、时区等。
使用 API 的示例:来自 IP 地址的位置
以下是更多
You can map an IP address to its location (city, country, postal code), timezone etc. with either a database or an API (hosted database).
Here's an example of using an API
more here : Location from IP address
你可以使用这个函数
调用该函数
U can use this function
Call the function
我建议您使用自托管 IP 记录,而不是使用第三方 API。这篇文章向您解释了更多
http://www.techsirius.com/ 2014/05/simple-geo-tracking-system.html
基本上他们使用的是maxmind的乡村城市IP数据库记录[http://dev.maxmind.com/geoip/geoip2/geolite2/] 进行少量修改。之后是示例查询
Instead of using third party API I would suggest you to use self hosted IP record. This post explain you more
http://www.techsirius.com/2014/05/simple-geo-tracking-system.html
Basically they are using maxmind's country city IP database record [http://dev.maxmind.com/geoip/geoip2/geolite2/] with few modifications. After that a sample query
编译这些数据库的一种方法是根据 whois 信息。例如,要确定 69.59.196.211 的位置:
显然这并不是非常准确,因此据称使用了更复杂的技术。
One way in which these databases are compiled is from whois information. For example, to determine the location of 69.59.196.211:
Obviously this isn't hugely accurate, so more sophisticated techniques are allegedly used.
如果地理定位功能对您的项目不是一个很大的要求,您可以使用像这样简单的东西:
您必须考虑到 freegeoip 的限制为 10k 请求/小时。
If the geolocation functionality is not a big requirement for your project, you can use something as simple as this:
You have to take into account that freegeoip has a limit of 10k request/hour.
大多数现有数据库使用来自国际注册机构 ARIN、AFRINIC、ANIC 等以及用户提交的位置的数据聚合。更复杂的技术包括拓扑和约束地理定位。
我运行自己的 API ipdata.co 提供多个数据点,包括国家、城市、地区、纬度/经度等。
Most of the existing databases use an aggregation of data from the international registries ARIN, AFRINIC, ANIC etc as well as user submitted locations. More sophisticated techniques include Topology and Constraints Geolocation.
I run my own API ipdata.co that provides several data points including, the country, city, region, lat/long and others.