用于确定 IP 地址所在城市和国家/地区的可靠 API

发布于 2024-08-24 05:56:07 字数 1539 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

卷耳 2024-08-31 05:56:07

考虑使用 geoplugin,它通过单行 PHP 代码提供最多信息,但每个请求都需要连接到 geoplugin.com 服务器(而且它是免费的)。

示例:

Json:http://www.geoplugin.net/json.gp ?ip=74.125.236.174

{
geoplugin_request: "74.125.236.174",
geoplugin_status: 200,
geoplugin_city: "Mountain View",
geoplugin_region: "CA",
geoplugin_areaCode: "650",
geoplugin_dmaCode: "807",
geoplugin_countryCode: "US",
geoplugin_countryName: "United States",
geoplugin_continentCode: "NA",
geoplugin_latitude: "37.419201",
geoplugin_longitude: "-122.057404",
geoplugin_regionCode: "CA",
geoplugin_regionName: "California",
geoplugin_currencyCode: "USD",
geoplugin_currencySymbol: "$",
geoplugin_currencySymbol_UTF8: "$",
geoplugin_currencyConverter: 1
}

XML:http://www.geoplugin.net/xml。 gp?ip=74.125.236.174

<geoPlugin>
<script/>
<geoplugin_request>74.125.236.174</geoplugin_request>
<geoplugin_status>200</geoplugin_status>
<geoplugin_city>Mountain View</geoplugin_city>
<geoplugin_region>CA</geoplugin_region>
<geoplugin_areaCode>650</geoplugin_areaCode>
<geoplugin_dmaCode>807</geoplugin_dmaCode>
<geoplugin_countryCode>US</geoplugin_countryCode>
<geoplugin_countryName>United States</geoplugin_countryName>
<geoplugin_continentCode>NA</geoplugin_continentCode>
<geoplugin_latitude>37.419201</geoplugin_latitude>
<geoplugin_longitude>-122.057404</geoplugin_longitude>
<geoplugin_regionCode>CA</geoplugin_regionCode>
<geoplugin_regionName>California</geoplugin_regionName>
<geoplugin_currencyCode>USD</geoplugin_currencyCode>
<geoplugin_currencySymbol>$</geoplugin_currencySymbol>
<geoplugin_currencySymbol_UTF8>
lt;/geoplugin_currencySymbol_UTF8>
<geoplugin_currencyConverter>1</geoplugin_currencyConverter>
</geoPlugin>

其他选项

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

{
geoplugin_request: "74.125.236.174",
geoplugin_status: 200,
geoplugin_city: "Mountain View",
geoplugin_region: "CA",
geoplugin_areaCode: "650",
geoplugin_dmaCode: "807",
geoplugin_countryCode: "US",
geoplugin_countryName: "United States",
geoplugin_continentCode: "NA",
geoplugin_latitude: "37.419201",
geoplugin_longitude: "-122.057404",
geoplugin_regionCode: "CA",
geoplugin_regionName: "California",
geoplugin_currencyCode: "USD",
geoplugin_currencySymbol: "$",
geoplugin_currencySymbol_UTF8: "$",
geoplugin_currencyConverter: 1
}

Xml : http://www.geoplugin.net/xml.gp?ip=74.125.236.174

<geoPlugin>
<script/>
<geoplugin_request>74.125.236.174</geoplugin_request>
<geoplugin_status>200</geoplugin_status>
<geoplugin_city>Mountain View</geoplugin_city>
<geoplugin_region>CA</geoplugin_region>
<geoplugin_areaCode>650</geoplugin_areaCode>
<geoplugin_dmaCode>807</geoplugin_dmaCode>
<geoplugin_countryCode>US</geoplugin_countryCode>
<geoplugin_countryName>United States</geoplugin_countryName>
<geoplugin_continentCode>NA</geoplugin_continentCode>
<geoplugin_latitude>37.419201</geoplugin_latitude>
<geoplugin_longitude>-122.057404</geoplugin_longitude>
<geoplugin_regionCode>CA</geoplugin_regionCode>
<geoplugin_regionName>California</geoplugin_regionName>
<geoplugin_currencyCode>USD</geoplugin_currencyCode>
<geoplugin_currencySymbol>$</geoplugin_currencySymbol>
<geoplugin_currencySymbol_UTF8>
lt;/geoplugin_currencySymbol_UTF8>
<geoplugin_currencyConverter>1</geoplugin_currencyConverter>
</geoPlugin>

Other options

情何以堪。 2024-08-31 05:56:07

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

一百个冬季 2024-08-31 05:56:07

我使用过 http://www.hostip.info/ 并发现它非常好。

I've used http://www.hostip.info/ and found it really good.

流心雨 2024-08-31 05:56:07

每个 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.

初雪 2024-08-31 05:56:07

从某种意义上说,您无法可靠地知道用户的位置。用户。使用其他答案提供的提示将为您提供 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.

空心空情空意 2024-08-31 05:56:07

谷歌有类似的东西吗?

不,Google 不提供类似的服务。 (请注意,这里的答案声称它确实提供了它,但没有结果)。

任何其他可帮助确定用户位置的免费或付费 API
他的IP

首先很难谈论这种服务的可靠性。大多数服务依赖 ISP 来获取数据,而 ISP 并不总是提供可靠的数据。此外,因为我假设您基本上关心用户的位置(而不是他的 IP 属于哪个位置),所以用户可以决定通过 VPN、Tor 或其他匿名器隐藏他的位置。

在您的一些评论中,我发现可靠意味着 API 提供商的正常运行时间。如果是这样,我会推荐 MaxMind 的 GeoIP2。首先,我已经看到这个网站很长时间了,它们更新得非常频繁(最后一次更新是2014年4月1日),而且如果你非常害怕停机 - 你可以下载他们的数据库并且不要依赖他们(而且他们是免费的)。

我真正喜欢的另一项服务鲜为人知且开源(它部分依赖于 MaxMind 的数据)。我只使用过它几次,所以我不能说它的正常运行时间,但我真的很喜欢他们的 API。它是如此简单,以至于很难想出更简单的:

http://www.telize.com/geoip/46.19.37.108 

或者像这样

http://www.telize.com/geoip/2a02:2770::21a:4aff:feb3:2ee

会给你

{
"country":"Netherlands",
"dma_code":"0",
"timezone":"Europe\/Amsterdam",
"area_code":"0",
"ip":"46.19.37.108",
"asn":"AS196752",
"continent_code":"EU",
"isp":"Tilaa V.O.F.",
"longitude":5.75,
"latitude":52.5,
"country_code":"NL",
"country_code3":"NLD"
}

我认为这两种服务足以为你的访问者获取正常信息。但有一点很重要。如果您确实需要知道用户来自哪里 - 为什么不使用 html5 地理位置 询问他们?这是一个不错的示例,但您可以更进一步(询问他们位置是否正确,并让他们能够更改它)。我知道在你的情况下你只需要国家/城市,但可能其他人会需要它。


PS 2015 年 11 月。 既然 telize.com 的使用需要付费,我发现了另一个目前免费的服务:

https://freegeoip.net/json/45.79.8.237
https://freegeoip.net/json/2600:3c00::f03c:91ff:fe98:c0f5

Does google have anything like this.

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).

Any other Free or paid API's that help determine user's location from
his IP

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:

http://www.telize.com/geoip/46.19.37.108 

or like this

http://www.telize.com/geoip/2a02:2770::21a:4aff:feb3:2ee

will give you

{
"country":"Netherlands",
"dma_code":"0",
"timezone":"Europe\/Amsterdam",
"area_code":"0",
"ip":"46.19.37.108",
"asn":"AS196752",
"continent_code":"EU",
"isp":"Tilaa V.O.F.",
"longitude":5.75,
"latitude":52.5,
"country_code":"NL",
"country_code3":"NLD"
}

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:

https://freegeoip.net/json/45.79.8.237
https://freegeoip.net/json/2600:3c00::f03c:91ff:fe98:c0f5
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文