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

7

20

I want a reliable API that can be used to determine a city and country from an IP address.

My search on Google led to http://ipinfodb.com/ip_location_api.php. It seems perfect but my only concern is the reliability of this service. Does google have anything like this?

I'm looking for free or paid APIs that help determine location from IP.

Atrophy answered 2/3, 2010 at 10:25 Comment(4)
Get city / country from IP : Your city , Your country , City for IP 8.8.8.8 , Country for IP 8.8.8.8Scriber
It's somewhat ironic that ipinfodb.com, the service you questioned all the way back in 2010, is still online and actually works just fine (been using it myself)Mignonne
curl -d "" "googleapis.com/geolocation/v1/geolocate?key=YOURAPIKEYTychon
developers.google.com/maps/documentation/geolocation/introTychon
I
7

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

Intransigence answered 2/3, 2010 at 10:28 Comment(2)
Just checked IP that is in use for 2 years. It even unable to locate my country. Not sure it's good for international lookups...Merci
I found that one ip-api.com/docs/api:json to be really good :)Fourwheeler
V
14

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

Variegate answered 1/12, 2012 at 7:33 Comment(2)
The only problem is that it has a restriction. Moreover you can be blocked.Skull
It does not work using https.Lepore
E
13

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

Environs answered 2/3, 2010 at 10:39 Comment(0)
I
7

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

Intransigence answered 2/3, 2010 at 10:28 Comment(2)
Just checked IP that is in use for 2 years. It even unable to locate my country. Not sure it's good for international lookups...Merci
I found that one ip-api.com/docs/api:json to be really good :)Fourwheeler
S
5

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.

Stovepipe answered 2/3, 2010 at 10:29 Comment(1)
Thanks SF - I probably used the wrong term - when I meant reliable - I meant to say the service should be quick and not have much down time. I understand we can never 100% correctly determine the location. This is just to prefill the form for the user which he can then change it if the city/country is wrongAtrophy
E
3

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.

Eutectoid answered 2/3, 2010 at 10:35 Comment(1)
Thanks Frank - I probably used the wrong term - when I meant reliable - I meant to say the service should be quick and not have much down time. I understand we can never 100% correctly determine the location. This is just to prefill the form for the user which he can then change it if the city/country is wrongAtrophy
M
3

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
Maskanonge answered 4/4, 2014 at 10:19 Comment(2)
currently i use freegeoip.net you can also try : geoplugin.net, may help someone.Pignut
can you confirm me is there any service of google which can provide country and country code of a given Ip address.Skull

© 2022 - 2024 — McMap. All rights reserved.