Know country’s name from IP Address

Sometimes I get amused how can someone get country’s name from IP-Address. If someone gets this info where does it store.

First, if you have any IP-Address it will look like this:

123.162.111.123

For example: 16.254.1.0 (if we are talking about IPv4 protocol).

Internet Assigned Numbers Authority (IANA) Manages IP-Addresses

The Internet Assigned Numbers Authority (IANA), is a non-profit organization which manages IP address distribution with the help of five RIRs (Regional Internet Registries) namely:

  1. African Network Information Center (AFRINIC) for Africa
  2. American Registry for Internet Numbers (ARIN) for the United States, Canada, several parts of the Caribbean region, and Antarctica.
  3. Asia-Pacific Network Information Centre (APNIC) for Asia, Australia, New Zealand, and neighboring countries
  4. Latin America and Caribbean Network Information Centre (LACNIC) for Latin America and parts of the Caribbean region
  5. Réseaux IP Européens Network Coordination Centre (RIPE NCC) for Europe, Russia, the Middle East, and Central Asia

These are also a non-profit organization which manages the distribution of IP address in their region and stores the data related to IP-address.

Now they sell the range of IP-address to the POC. Then these POC update the database of the respective RIRs.

That is how this large database is managed.

If we talk about Country’s Info regarding the IP address. RIRs save details of IP ranges assigned to the country.

In the below-mentioned link, you will get the Info what range of IP address assigned to which RIRs

http://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xhtml

List of Url to find IP-Address

List of IP address assigned by

APNIC to the country found in the below-mentioned link:

ftp://ftp.apnic.net/apnic/stats/apnic/assigned-apnic-latest

ARIN to the country found in the below-mentioned link:

ftp://ftp.apnic.net/public/stats/arin/delegated-arin-extended-latest

AFRINIC to the country found in the below-mentioned link:

ftp://ftp.afrinic.net/stats/afrinic/delegated-afrinic-extended-latest

LACNIC to the country found in below-mentioned link:

ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-extended-latest

To get the range of IP address assigned to the country

afrinic|ZA|asn|1228|1|19910301|allocated|F36B9F4B

You will need to convert your IP address to IP number

  1. The process to convert your IP address 192.168.1.2 to IP number are as follows:

192 x (256) ^ 3 + 168 x (256) ^ 2 + 1 x (256)^1 + 2 (256)^ 0 = ?      3221225472 + 11010048 + 256 + 2 = 3232235778
  1. If you want to convert IP number to IP address is as follows:

[3232235778/256^3] % 256 = 192

[3232235778/256^2] % 256 = 168

[3232235778/256^1] % 256 = 1

[3232235778/256^0] % 256 = 0