#!/usr/bin/perl ######################################################################################## # Anastasios Monachos - anastasiosm@gmail.com # # Usage ./generate.full.ips.pl ip-ranges.txt > ip-ranges-expanded.txt # #Download from ftp://ftp.ripe.net/ripe/stats/ the list of allocated ips for Europe, #similar ip delegation files can be found on ARIN etc. The files have the following #format: # ripencc|GB|ipv4|62.3.64.0|16384|20010629|allocated # ripencc|SE|ipv4|62.3.128.0|8192|20001005|allocated # ripencc|PL|ipv4|62.3.160.0|8192|20020114|allocated # ripencc|GB|ipv4|62.3.192.0|16384|20030212|allocated # ripencc|FR|ipv4|62.4.0.0|8192|19970513|allocated # # using the command # cat ripencc-delegation.txt | awk -F\| '{if ($2=="GB") print $4;}' > uk.txt #you can extract ips allocated to companies' in the United Kingdom (GB) # open the saved file eg uk.txt as you migth have to delete some lines that do not # correspond to ipv4 address format) # # # Or alterantive just create a file with contents of the format x.y.0.0 or x.y.z.0 # and pass to the script so to produce all IPs in the range x.y.255.255 and x.y.z.255 ####################################################################################### $filename = shift; open (FILE,"<$filename") or die "Couldn't open the file!"; while () { $line=$_; ($first, $second, $third, $forth) = split('\.',$line); if ($first>0 && $first<256 && $second>0 && $second<256 && $third=~ "0" && $forth=~ "0" && length($third)=~"1" )# x.y.0.0 where x,y not 0 and smaller than 256 { for ($count = 0; $count<=255; $count++) { for ($countin = 0; $countin<=255; $countin++) { print $first,".",$second,".",$count,".",$countin,"\n"; } } } elsif ($first>0 && $first<256 && $second>0 && $second<256 && $third>0 && $third<256 && $forth=~ "0" ) { for ($count = 0; $count<=255; $count++) { print $first,".",$second,".",$third,".",$count,"\n"; } } } close(FILETOOPEN);