[117604] in North American Network Operators' Group
Re: subnet aggregation script
daemon@ATHENA.MIT.EDU (Jeff Walter)
Mon Sep 21 19:43:12 2009
Date: Mon, 21 Sep 2009 16:42:08 -0700
From: Jeff Walter <jeffw@he.net>
To: Ric Moseley <rmoseley@softlayer.com>
In-Reply-To: <98E72206041B1B408D3F92E91E80BF1802750530@slmail101.softlayer.local>
Cc: nanog@nanog.org
Errors-To: nanog-bounces+nanog.discuss=bloom-picayune.mit.edu@nanog.org
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 ()));