Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location from ip address

Tags:

ip-address

Do you know of any service which given an ip address it returns a location/country? I found a few lists we can add to our database but do I need to update them often? Is there any rule (like telephone numbers) to know the country of origin?

Sorry, I know this might sound a stupid question but for what we're doing it can't fail.

EDIT: I forgot to mention this has to be accessible programmatically (PHP)

Thanks :) Diogo

like image 998
DiogoNeves Avatar asked Nov 02 '10 16:11

DiogoNeves


People also ask

Can you get location from IP address?

The IP address routes Internet traffic to your computer. To clarify, it does not reveal your location. If someone was able to get your IP address they could learn a bit about your Internet service, such as which provider you use to connect to the Internet, but they really can't locate you, your home, or your office.

How do I find location of an IP address?

You may also use 3rd party websites such as Geobytes or Dnsstuff to lookup the IP address. The whois lookup will reveal name of the ISP who owns that IP address, and the country where it is originated from. If you're lucky, you might also find the city of orgin.


1 Answers

Check this out: http://www.farhad.ca/2011/06/15/rbl-based-ip-to-location/

Assume IP address of question is 10.11.12.13, then here is a sample:

<?php

$ip_address = gethostbyname('13.12.11.10.rbloc.dayanadns.com');
list($d1,$d2,$d3,$d4) = explode('.',$ip_address);
$country_code = chr($d3).chr($d4);

print "Result address: ".$ip_address."\n";
print "Country code: ".$country_code."\n";

?>
like image 86
Farhad Malekpour Avatar answered Oct 20 '22 06:10

Farhad Malekpour