Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get region/city from ip [closed]

Tags:

how can I retrieve the region and the city from an ip? I have found this service: http://api.hostip.info/?ip=xyz.qwe.rty

But It doesn't give me accurate info like this: http://www.ipaddresslocation.org/

Do you know some free service? I need to retrieve this info with a php script, but I wouldn't install external library.

Thank you so much

like image 847
michele Avatar asked Jun 14 '11 21:06

michele


People also ask

Can you get city from IP address?

To reiterate, however, an IP address isn't enough. You need to use a geolocation database to obtain this user information. The most basic information provided in most geolocation databases includes the continent, country, state/region, city, and time zone of the electronic device.

Can IP change geolocation?

ISP improvements and growthISPs update their databases for accuracy, and this can cause IP addresses to change. Take, for instance, this geolocation change we recently noticed. The geolocation update is most likely due to improvements and updates in ISPs databases.

Can you tell country from IP address?

No you can't - IP addresses get reallocated and reassigned from time to time, so the mapping of IP to location will also change over time. GeiLite seems legit. I didn't know there are so many geonames. Takes a bit of time to insert into the database parsed.


1 Answers

http://ipinfo.io, my service, gives you city, country and other related information about an IP:

$ curl ipinfo.io/8.8.8.8 {   "ip": "8.8.8.8",   "hostname": "google-public-dns-a.google.com",   "loc": "37.385999999999996,-122.0838",   "org": "AS15169 Google Inc.",   "city": "Mountain View",   "region": "CA",   "country": "US",   "phone": 650 } 

Here's a PHP example:

$details = json_decode(file_get_contents("http://ipinfo.io/".$_SERVER['REMOTE_ADDR']")); echo $details->city; // -> "Mountain View" 
like image 155
Ben Dowling Avatar answered Oct 01 '22 01:10

Ben Dowling