Reliable API to determine an ip address's city and country [closed]

送分小仙女□ 提交于 2019-11-29 20:30:39

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

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

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>&#36;</geoplugin_currencySymbol>
<geoplugin_currencySymbol_UTF8>$</geoplugin_currencySymbol_UTF8>
<geoplugin_currencyConverter>1</geoplugin_currencyConverter>
</geoPlugin>

Other options

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.

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!