You can use GeoIP to look up the country associated with a given IP address (you can also give it a hostname to determine the country). To create the GeoIP program geoiplookup, you can download the C source code from http://www.maxmind.com/app/c. You will need a C compiler to compile the code. If you intend to use it on a Linux or Unix system, you will have a C compiler on the system, so just follow the instructions below to create the geoiplookup program or read the INSTALL file that comes with the file you download from the MaxMind website. If you intend to install it on a Windows system, read the READMEwin32.txt file that is in the .gz file you download.
Unzip the downloaded file, extract the contents of the resultant tar file and then change the working directory to the GeoIP directory created from the contents of the tar file.
gunzip GeoIP-1.3.6.tar.gz
tar -xvf GeoIP-1.3.6.tar
cd GeoIP-1.3.6
Then run the configure
and make
commands
(installation instructions are in the INSTALL file created in the GeoIP
directory, but are also summarized here).
./configure
make
You can then issue the command make check
to run self-tests of
the package, but this step isn't required. You should then type
make install
to install the software.
make test
make install
At this point you won't need the program binaries and other files in
the source code directory and they can be removed with make
clean
. You can also remove the files created by configure
by issuing the command make distclean
. You can also remove the
GeoIP directory and its contents, if you wish, since make install
installs the package's files in /usr/local/bin, /usr/local/man, etc.
make clean
make disclean
cd ..
rm -fr GeoIP-1.3.6
When the program is installed, you will have a geoiplookup program in /usr/local/bin. You can use that program to lookup the country associated with an IP address or hostname. The country is based on the registration for the IP address, i.e. particular blocks of IP addresses will be associated with particular countries or at least areas of the world. The company using the IP address may be based in some other country, however. For example:
geoiplookup eapplique.com
GeoIP Country Edition: US, United States
The company has their website, eapplique.com, hosted on a server with
a US IP address. But if you issue the command whois
eapplique.com
, you will see the domain
name is registered to a company in India (the company provides website
design services). So geoiplookup gives you an indication of where a
server is likely to be located, but not necessarily the location of a
particular company using that server. Companies and individuals may
use servers located in other countries.
Registrant:
THE SCS GROUP (EAPPLIQUE-DOM)
K 3/17, DLF Phase II
GURGAON, HARYANA 122002
IN
Domain Name: EAPPLIQUE.COM
For an example of a lookup for an IP address, here is another example:
geoiplookup 202.64.156.35
GeoIP Country Edition: HK, Hong Kong