« Home | Tracking Visitors To Your Blog Site - Part I » | A Brief Intro To GIS (Geographical Information Sys... » | Geoplotting Your Web and Blog Site Visitors »

Saturday, September 03, 2005

IP Address To Country Conversion

One of the concepts that we are going to be revisting several times in this blog is the conversion of IP addresses to the corresponding country code. From a standard, two-letter country code, we can derive country names. The reason this is relatively easy to do is because every country is assigned a one or more blocks of consecutive IP addresses. The current IPV4 (IP Version 4) protocol uses IP addresses that have four parts. An example is, which is a reserved address that actually refers to your personal computer, which is also known as "localhost". There are also reserved blocks of IP addresses that you can use to setup a home or office network. These addresses, because they are internal to a network, can be reused all over the world.

Each of the four parts of an IP address can be from 0 to 255. Consecutive blocks can occur on any of the four parts. The larger a country is, the bigger the block. For example, a big country may have a block such as assigned to them. This block represents (159-144)x255x255x255 = (15)x16,581,375 = 248,720,625 Internet addresses. A small country may have a block such as, which is (255x255) = 65,025 addresses. Countries are allowed to have more than one block.

Since blocks of IP addresses have been pre-assigned to every country, provided you have acccess to this assignee list, it's easy to determine what country a visitor to your website or blogsite is from. Determining the city they are from is a bigger effort, but it is also possible. However, current efforts are reported to have a 95-98% accuracy. The methods used to produce an IP-to-City list are closely guarded secrets. But if you have the patience, I'm hoping to reveal that information in this blog. Note that the websit.es that I have downloaded IP-to-Country lists from have a TOS (Terms of Service) that states their list not be redistributed. However, there are ways to produce your own list, which I will reveal

As it takes me a bit of research and testing to write each posting, I am probably only going to be posting to this blog once or twice a week until I have some research completed. Perl or PHP scripts will, as I've mentioned before, be made available at the Perl-Tips or PHP-Tips blogs, as available.

(c) Copyright 2005-present, Raj Kumar Dash, http://geoplotting.blogspot.com

E-mail this post

Remenber me (?)

All personal information that you provide here will be governed by the Privacy Policy of Blogger.com. More...

Add a comment


GeoPlotting Journal

This weblog/journal deals with a variety of topics relating to geographical data, as well as GIS (Geographical Information Systems) software and GPS devices. Posting is currently suspended, until a new version of this journal has been developed.

About Me
I'm a geek/ philosopher/ composer/ artist/ cook/ photographer/ web programmer/ consultant/ blah-blah-blah who is also a published writer and author. I worked with GIS systems and cartographic projections for seven years. I've had a love of maps and globes ever since my father gave me an atlas when I was in grade school. This is one of several blogs that I write.

Web geoplotting

(c) Copyright: 2005-present, Raj Kumar Dash, http://geoplotting.blogspot.com/