I feel compelled to point out a perl script I found while researching a recent event.
The issue: I wanted to find all subnets for a particular region, then find the least number of CIDR blocks.
After finding the subnets, I needed to find the fewest CIDR blocks possible. While this can be done mentally, I was dealing with a list of hundreds of subnets, with few that were contiguous (and this happens often).
Queue the perl script. Call the script against a text file containing the subnets.
'perl CIDR.pl subnets.txt'
Contents of the infile:
192.168.2.0/23
192.168.3.0/24
192.168.4.0/24
192.168.5.0/24
192.168.6.0/23
192.168.7.0/24
192.168.8.0/25
192.168.8.128/25
192.168.10.0/24
192.168.11.0/24
172.16.4.0/24
172.16.5.0/24
127.16.6.0/23
subnets.txt (END)
192.168.3.0/24
192.168.4.0/24
192.168.5.0/24
192.168.6.0/23
192.168.7.0/24
192.168.8.0/25
192.168.8.128/25
192.168.10.0/24
192.168.11.0/24
172.16.4.0/24
172.16.5.0/24
127.16.6.0/23
subnets.txt (END)
Output:
127.16.6.0/23
172.16.4.0/23
192.168.2.0/23
192.168.4.0/22
192.168.8.0/24
192.168.10.0/23
outfile.txt (END)
172.16.4.0/23
192.168.2.0/23
192.168.4.0/22
192.168.8.0/24
192.168.10.0/23
outfile.txt (END)
There are multiple instances where this can be useful: route summarization, efficient/reduced ACL entries, etc. The script can be found here: http://www.uq.edu.au/~suter/software/aggregate-cidr-addresses/
As always, YMMV and check the hashes. The script has definitely helped me. Thank you Mark Suter.


