Jan 092008
Here’s a quick script to figger out [sub]totals of a list of IP ranges. Easy, but handy.
Like:
$ cat testips.txt
10.1.16/24
10.7
10.14.15.1-10.14.15.127
10.22.3.0
$ ./figgerips.pl < testips.txt
IP Range: 10.1.16/24
Size: 256
Total: 256
IP Range: 10.7
Size: 1
Total: 257
IP Range: 10.14.15.1-10.14.15.127
Size: 127
Total: 384
IP Range: 10.22.3.0
Size: 1
Total: 385
#!/usr/bin/perl
# usage: ./figgerips.pl < testips.txt
use Net::IP;
my $total;
$total = 0;
while (<>)
{
my $ip = new Net::IP ($_) or die (Net::IP::Error());
$total += $ip->size();
print ("IP Range: $_" . "Size: " . $ip->size()."\n");
print "Total: " . $total . "\n\n";
}
Sorry, the comment form is closed at this time.