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 127.0.0.1, 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 144.0.0.0-159.255.255.255 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 160.0.0.0-160.0.255.255, 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
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 144.0.0.0-159.255.255.255 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 160.0.0.0-160.0.255.255, 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