Skip to content

Generating country IP ranges lists #2

  • by

My original article about this topic is more that year old and was using Regional Internet Registries (RIRs) list as source and was in python. This post will describe other simple solution how to generate some country IP ranges list.

We can use Maxmind GeoLite database file This time, script is in php. It will download zipped file into /tmp, and generate $country.cidr files in current directory.

echo "Downloading...\n";
echo "Generating";
while (($line = fgetcsv($f,0,',')) !== FALSE) {
        if ((($c++) % 1000==0)) echo ".";
        if (strpos($mask,'INF')!== false) $mask='32';

echo "\n";
foreach ($data as $country => $ranges) {
        echo "Writing $country\n";
        array_unshift($ranges,"# Generated ".date('r')."\n");

Which one do you like more?

Leave a Reply

Your email address will not be published. Required fields are marked *