-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcompactaddrs.pl
More file actions
executable file
·43 lines (33 loc) · 846 Bytes
/
Copy pathcompactaddrs.pl
File metadata and controls
executable file
·43 lines (33 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -T
use strict;
use warnings;
# compactaddrs - aggregate addr blocks
use NetAddr::IP qw( Compact :lower );
use Net::IP qw (:PROC);
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);
for my $prefix (@aggregates) {
print "$prefix\n";
}
}
if ( scalar @v6blocks > 0 ) {
# print " #IPv6 aggregate prefixes\n";
my @aggregates = Compact(@v6blocks);
for my $prefix (@aggregates) {
my ($net6, $mask6) = split /\//, $prefix, 2;
print lc(ip_compress_address($net6, $mask6)),"/$mask6\n";
}
}
#print "\n";