mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-17 08:38:42 +00:00
21 lines
492 B
Plaintext
21 lines
492 B
Plaintext
|
#!/usr/bin/perl
|
||
|
#
|
||
|
# Convert Cisco routing table listing to list of prefixes
|
||
|
#
|
||
|
|
||
|
$loc = ($ARGV[0] eq "-l"); # Print only local prefixes
|
||
|
|
||
|
while (<STDIN>) {
|
||
|
($loc ? /^[OR]\s/ : /^B\s/) || next;
|
||
|
/^[ORB]( E[12])?\s+(\d+\.\d+\.\d+\.\d+)(\s|\/\d+\s)/ || die "Cannot parse $_";
|
||
|
$net = $2;
|
||
|
$len = $3;
|
||
|
if ($len =~ /^\s*$/) {
|
||
|
# Magic rule :)
|
||
|
$len = ($net =~ /\.0$/) ? 24 : 32;
|
||
|
}
|
||
|
$len =~ s/^\///;
|
||
|
$net =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;
|
||
|
printf "%02x%02x%02x%02x/%d\n", $1, $2, $3, $4, $len;
|
||
|
}
|