We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(7)
考虑使用 geoplugin,它通过单行 PHP 代码提供最多信息,但每个请求都需要连接到 geoplugin.com 服务器(而且它是免费的)。
示例:
Json:http://www.geoplugin.net/json.gp ?ip=74.125.236.174
XML:http://www.geoplugin.net/xml。 gp?ip=74.125.236.174
其他选项
Consider using geoplugin, it provides the most information from a single line PHP code, but requires a connection to the geoplugin.com server for every request (and it is free).
Examples :
Json : http://www.geoplugin.net/json.gp?ip=74.125.236.174
Xml : http://www.geoplugin.net/xml.gp?ip=74.125.236.174
Other options
MaxMind 有 ip2country 和 ip2city 数据库的精简版:
http://www.maxmind.com/app/geolitecity
http://www.maxmind.com/app/geolitecountry
如果您不介意自己托管数据库,它是免费的。
有偿服务更精准。
他们还提供用于查询的网络服务,但不是免费的:
http://www.maxmind.com/app/web_services#country
MaxMind has a lite version of their ip2country and ip2city databases:
http://www.maxmind.com/app/geolitecity
http://www.maxmind.com/app/geolitecountry
If you don't mind hosting the database yourself, it's free.
The paid services are more accurate.
They also provide web services for querying, but it is not free:
http://www.maxmind.com/app/web_services#country
http://www.ip2location.com/
Google 提供免费服务http://briancray.com/2009/05/29/find-web-visitors-位置-javascript-google-api/
http://www.ip2location.com/
Google has free service http://briancray.com/2009/05/29/find-web-visitors-location-javascript-google-api/
我使用过 http://www.hostip.info/ 并发现它非常好。
I've used http://www.hostip.info/ and found it really good.
每个 IP 地理位置都取决于 ISP 提交的记录。这永远不会完全可靠,因为许多 ISP 提交的是其办公室的位置,而不是其子网的物理位置,而子网的物理位置可能位于不同的城市甚至国家。
Every IP geolocation depends on records submitted by the ISP. This will never be completely reliable because many ISPs submit location of their office instead of physical locations of their subnets which may be in a different city or even country.
从某种意义上说,您无法可靠地知道用户的位置。用户。使用其他答案提供的提示将为您提供 IP 的地理位置,但无法知道美国纽约的 IP 地址是否由出差到英国伦敦或的某人通过 VPN 访问是否有人使用 Tor 等匿名服务。
In a sense, you can't reliably know the location of a user. Using the tips the other answers provide will give you the geolocation of an IP, but there's no way to know that that IP address in New York USA isn't being accessed through a VPN from someone on a business trip to London, UK, or whether someone's using an anonymizing service like Tor.
不,Google 不提供类似的服务。 (请注意,这里的答案声称它确实提供了它,但没有结果)。
首先很难谈论这种服务的可靠性。大多数服务依赖 ISP 来获取数据,而 ISP 并不总是提供可靠的数据。此外,因为我假设您基本上关心用户的位置(而不是他的 IP 属于哪个位置),所以用户可以决定通过 VPN、Tor 或其他匿名器隐藏他的位置。
在您的一些评论中,我发现可靠意味着 API 提供商的正常运行时间。如果是这样,我会推荐 MaxMind 的 GeoIP2。首先,我已经看到这个网站很长时间了,它们更新得非常频繁(最后一次更新是2014年4月1日),而且如果你非常害怕停机 - 你可以下载他们的数据库并且不要依赖他们(而且他们是免费的)。
我真正喜欢的另一项服务鲜为人知且开源(它部分依赖于 MaxMind 的数据)。我只使用过它几次,所以我不能说它的正常运行时间,但我真的很喜欢他们的 API。它是如此简单,以至于很难想出更简单的:
或者像这样
会给你
我认为这两种服务足以为你的访问者获取正常信息。但有一点很重要。如果您确实需要知道用户来自哪里 - 为什么不使用 html5 地理位置 询问他们?这是一个不错的示例,但您可以更进一步(询问他们位置是否正确,并让他们能够更改它)。我知道在你的情况下你只需要国家/城市,但可能其他人会需要它。
PS 2015 年 11 月。 既然 telize.com 的使用需要付费,我发现了另一个目前免费的服务:
No, Google does not provide a service similar to this. (note that the answer here which claims that it does provide it, leads to nowhere).
First of all it is hard to speak about reliability of such service. Most of the services rely on ISP to get their data and ISP not always provide reliable data. Moreover because I assume that you basically cares about the location of your user (and not what location his IP belongs), the user can decide to hide his location either through VPN, Tor or other anonymisers.
In some of your comments, I have seen that by reliable you means uptime of the API provider. If so, than I would recommend MaxMind's GeoIP2. First of all, I have seen this site for long time, they are updated pretty often (last update 1-st April 2014), moreover if you are so afraid of downtime - you can download their database and do not rely on them (also they are free).
Another service I actually like is less known and opensource (it partially relies on data from MaxMind). I have used it only a few times, so I can not say about it's uptime, but I really like theirs API. It is so simple, that it is hard to come up with simpler:
or like this
will give you
I think that these two services are pretty enough to get normal information for your visitors. But one important thing. If you really need to know where you users came from - why not to ask them with html5 geolocation? Here is a nice example, but you can go further (ask them if the location is correct and give them ability to change it). I know that in your case you need only Country/City, but may be other people will need it.
P.S. Nov 2015. Now that telize.com costs money to use, I found another service that is currently free: