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.