Entry
How can I find a clients geographical location from their IP address?
May 16th, 2002 17:40
TJ Mather, Per M Knutsen, peter kelly,
There is no simple one-to-one correspondence between IP addresses and
the physical location of the host. If the IP address translates to a
domain name, you can derive the host's TLD (country code) with Perl's
gethostbyaddr function. This simple script will print out the host name
of a user supplied address:
#!/usr/bin/perl
use Socket;
$ipaddr = inet_aton(@ARGV);
print gethostbyaddr ($ipaddr, AF_INET)."\n";
Run as ./ip2host.pl xxx.xxx.xxx.xxx
Geo::IP is a Perl module that looks up the country based on IP
address. To download, go to
http://kobesearch.cpan.org/search?dist=Geo-IP