#!/usr/bin/perl # Zero out the counters $CIDRCount=0; $IPCount=0; # make a hash table because it is faster to do the math once for each CIDR mask # instead of once for each CIDR block. %CIDRNum=(); for ($Num = 0; $Num < 33; $Num++) { $CIDRNum{$Num}=2**(32-$Num); } while (<>) { chomp $_; if ($_ =~ /.*\/.*/) { # Take CIDR block input (ip/cidrmask) $CIDRCount++; ($Net,$CIDRMask)=split (/\//,$_,2); $IPCount=$IPCount+$CIDRNum{$CIDRMask}; } else { # Take individual IPs (pf doesn't show the /32) $CIDRCount++; $IPCount++; } } print "CIDR Blocks: $CIDRCount\n"; print "IP Addresses: $IPCount\n";