File: cisco2list

package info (click to toggle)
bird2 2.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,644 kB
  • sloc: ansic: 75,250; sh: 3,807; perl: 3,444; lex: 887; xml: 520; makefile: 511; python: 495; sed: 13
file content (20 lines) | stat: -rwxr-xr-x 492 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/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;
}