IP to Country
About
A TCL script that maintains IP to Country mappings in a MySQL database.
Step 1:
Edit lines 28->30 in ip2c.tcl to match your environment.
Step 2:
~Ip2c$ cat ip2c.sql | mysql -u <user> -p
Step 3:
~ Ip2c$ ./ip2c.tcl
Fetching AFRINIC Checksum..
Bookmark not found, Fetching AFRINIC Data.
Verifying transfer.. Looks good, processing..
Processed 1498 IPv4 records and skipped 613.
Fetching APNIC Checksum..
Bookmark not found, Fetching APNIC Data.
Verifying transfer.. Looks good, processing..
Processed 16450 IPv4 records and skipped 4423.
Fetching ARIN Checksum..
Bookmark not found, Fetching ARIN Data.
Verifying transfer.. Looks good, processing..
Processed 40746 IPv4 records and skipped 20262.
Fetching LACNIC Checksum..
Bookmark not found, Fetching LACNIC Data.
Verifying transfer.. Looks good, processing..
Processed 2369 IPv4 records and skipped 1582.
Fetching RIPE Checksum..
Bookmark not found, Fetching RIPE Data.
Verifying transfer.. Looks good, processing..
Processed 37157 IPv4 records and skipped 20210.
Updating database..
Step 4:
mysql> SELECT * FROM mappings WHERE INET_ATON('74.125.91.104') <=end_ip ORDER BY end_ip ASC LIMIT 1;
Notes:
1) This script currently does not process ipv6 addresses.
2) Create a cron job to run the script at least a few times a week.
3) This script has not been extensively tested and is offered 'As is'.
Download: