Extracting the Country from the IP Address:- How To?

The Database

There are many services, both Free & Commercial, which provide you the geographic data of the visitors to your website. We will however use the free IP-Country database provided by
http://ip-to-country.webhosting.info. This database is available in the CSV format & can be imported into other databases like MS-Access, MS-SQL, MySQL, etc. Since we will be using ASP & MS-Access, we will thus download this csv database & import it into an MS-Access database.
The MS-Access database containing the records from the downloaded csv database is attached with this tutorial. The full code used in this tutorial is at the end.

So after importing the CSV file into an MS-Access database, we name the database as ip2country & the table as ip2c.
Now, there are 5 columns in our table ip2c, namely, ip_from, ip_to, co_code2, co_code3 & co_name.
Instead of storing IP Address, which are in format xxx.xxx.xxx.xxx, this database has IP number ranges. The ip_from marks the beginning of range & ip_to ends it. The co_code2 column has the 2Digit country code & co_code3 has 3Digit Country Code. The column co_name has the full country name.

Now we will proceed to writing the ASP code.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Engineers are all basically high-functioning autistics who have no idea how normal people do stuff.” - Cory Doctorow