NAME

rdbms_reg.pl - generates a complete list of IP-country codes using a relational database

SYNOPSIS

./rdbms_reg.pl dbi:mysql:foo fred passw0rd

IMPORTANT

Note that it is *not* necessary to run this script to install the IP::Country modules. It is only included with this distribution for completeness, so that you will be able to work out the entire process of converting raw Internet registry files to the fast database used by the bundled modules.

The output of this script can be found in the file named ./sorted_ranges.txt

DESCRIPTION

The files distributed by the regional Internet registries (included with this distribition under the ./rir_data directory) contain ranges of IP addresses that have been allocated to ISPs in various countries.

To produce a fast database for the IP::Country modules, it is essential to know not only the allocated ranges, but also the unallocated ranges. It is also advantageous to concatenate abutting ranges allocated to the same country.

This script does all this, and prints (to STDOUT) a list of ranges covering the entire IPv4 space, in the following format:

dotted_ip|size_of_range|country_code

For example:

64.39.224.0|4096|US
64.39.240.0|4096|--
64.40.0.0|16384|US
64.40.64.0|8192|US
64.40.96.0|4096|CA

Where coutry_code is the two-letter international country code, or '--' for an unallocated range, or '**' for a private range (see RFC1918).

DATABASE SCHEMA

This script should work with most relational databases, so long as a table exists with the following column definitions:

start INT UNSIGNED
end INT UNSIGNED
cc CHARACTER (2)

I have enclosed a schema that can be used with MySQL as the file ./mysql_schema.sql

I would welcome bug reports or patches if you notice problems using this script with any other database systems.