nanog mailing list archives
Re: CIDR cleanup
From: John Kristoff <jtk () depaul edu>
Date: Thu, 1 Oct 2020 16:29:11 -0500
On Thu, 1 Oct 2020 13:32:53 +0000 John Von Essen <john () essenz com> wrote:
I tried to write my code to do this, and its not trivial, just lookinh for a shortcurt. I did a breif glance at some CIDR related Perl cpan modules, and nothing has jumped out.
I wrote the code below some time ago. I've not used it in awhile, but
presumably it does what I think it does. I called it compactaddrs.pl.
Feed it a list of CIDR blocks via stdin.
John
#!/usr/bin/perl -T
use strict;
use warnings;
# compactaddrs - aggregate addr blocks
use NetAddr::IP qw( Compact );
my @v4blocks;
my @v6blocks;
while( defined(my $line=<>) ) {
chomp $line;
if ( $line =~ /:/ ) {
push @v6blocks, NetAddr::IP->new($line);
}
else {
push @v4blocks, NetAddr::IP->new($line);
}
}
if ( scalar @v4blocks > 0 ) {
print "# IPv4 aggregate prefixes\n";
my @aggregates = Compact(@v4blocks);
print 'WHERE';
for my $prefix (@aggregates) {
print ' saddr <<= ';
print "'$prefix' OR";
# print "$prefix\n";
}
}
if ( scalar @v6blocks > 0 ) {
print " #IPv6 aggregate prefixes\n";
my @aggregates = Compact(@v6blocks);
for my $prefix (@aggregates) {
print "$prefix\n";
}
}
print "\n";
Current thread:
- CIDR cleanup John Von Essen (Oct 01)
- Re: CIDR cleanup Tim Jackson (Oct 01)
- Re: CIDR cleanup Jon Meek (Oct 01)
- Re: CIDR cleanup Marcos Manoni (Oct 01)
- Re: CIDR cleanup Job Snijders (Oct 02)
- Re: CIDR cleanup Randy Bush (Oct 02)
- Re: CIDR cleanup Job Snijders (Oct 02)
- Re: CIDR cleanup Randy Bush (Oct 02)
- Re: CIDR cleanup Job Snijders (Oct 02)
- Re: CIDR cleanup Markus Weber (FvD) (Oct 02)
- Re: CIDR cleanup Tim Jackson (Oct 01)
- <Possible follow-ups>
- Re: CIDR cleanup Charles Cloughly (Oct 01)
- Re: CIDR cleanup John Kristoff (Oct 01)
