subnet aggregation script

Does anyone know of a tool/script that can aggregate subnets feed to it
via command line? Meaning if I give it multiple /30s (or any size
subnet) it will scrunch them together.

Example:

#aggregate_subnets.script 192.168.0.0/30 192.168.0.4/30 10.0.0.16/29
10.0.0.24/29

#192.168.0.0/29 10.0.0.16/28

Thanks.

Ric Moseley

VP of Engineering

rmoseley@softlayer.com

214-442-0555 direct

972-989-7813 cell

214-442-0600 office

866-398-7638 toll-free

214-442-0601 fax

6400 International Parkway, Suite 2000
Plano, TX 75093

The contents of this email message and any attachments are confidential and are intended solely for the addressee. The information may also be legally privileged. This transmission is sent in trust for the sole purpose of delivery to the intended recipient. If you have received this transmission in error; any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply email and delete this message and all associated attachments.

image001.gif

netmask:

netmask 192.168.0.0/30 192.168.0.4/30 10.0.0.16/29
      10.0.0.16/29
    192.168.0.0/29

Certainly available in the ubuntu repositories.

Does anyone know of a tool/script that can aggregate subnets feed to it
via command line? Meaning if I give it multiple /30s (or any size
subnet) it will scrunch them together.

I wrote this years ago and we used it in 6461 for various things.

ftp://ftp.isc.org/isc/aggregate/aggregate-1.6.tar.gz

Example:

#aggregate_subnets.script 192.168.0.0/30 192.168.0.4/30 10.0.0.16/29
10.0.0.24/29

#192.168.0.0/29 10.0.0.16/28

[octopus:~]% cat >input-file
192.168.0.0/30
192.168.0.4/30
10.0.0.16/29
10.0.0.24/29
[octopus:~]%
[octopus:~]% aggregate <input-file >output-file
aggregate: maximum prefix length permitted will be 32
[octopus:~]% cat output-file
10.0.0.16/28
192.168.0.0/29
[octopus:~]%

It's quite bad at dealing with really long lists, but it's ok for small applications. There's a manual page, and options, and stuff. You can make it show its working, if you're worried about whether it is sane.

[octopus:~]% aggregate -v <input-file
aggregate: maximum prefix length permitted will be 32
[ 0] + 10.0.0.16/28
[ 0] + 192.168.0.0/29
[ 1] - 192.168.0.0/30
[ 2] - 192.168.0.4/30
[octopus:~]%

I forget exactly what the numbers in the brackets mean, but from memory 0 means it's a generated prefix and anything else refers to a line number in the input stream. No doubt the source would provide illumination.

I don't remember why I thought it was a good idea to spit out the "maximum prefix length" warning to stderr every time.

Joe

Ric Moseley wrote:

Does anyone know of a tool/script that can aggregate subnets feed to it
via command line? Meaning if I give it multiple /30s (or any size
subnet) it will scrunch them together.

Here is a Perl script to do just that. My normal one reads from STDIN.

#!/usr/bin/perl

use Net::CIDR::Lite;

my $cidr = Net::CIDR::Lite->new ();

foreach (@ARGV) {
  if (/^[0-9a-f\.:]+(\/\d+)?$/) {
                  $cidr->add_any ($_);
         }
}

print (join ("\n", $cidr->list ()));