#!/bin/perl use Net::Telnet::Cisco; $router = "10.10.10.4"; $port = 23; my $cs = Net::Telnet::Cisco->new( Host => $router, Input_log => "Input22.log", Port => $port,); $cs->login( 'cisco', 'cisco' ); $password="cisco123"; $cs->enable( $password ); open(OUTPUT, "> $ARGV[1]") or die "ERROR opening $ARGV[1]: $!n"; open(PREFIXES, "< $ARGV[0]") or die "ERROR opening $ARGV[0]: $!n"; open(ASFILE, "< asnames.txt") or warn "Can not open asnames.txt: $!n"; while () { /AS(d+?) (.*)/; $as{$1} = "$2"; } close(ASFILE); $path_num = 0; @cmd_output = $cs->cmd( 'term len 0' ); while () { chomp; if (!/^#/) { $prefix = $_; @cmd_output = $cs->cmd( "sh ip bgp $prefix" ); foreach (@cmd_output) { chomp; # Insert a single ASN of a well-connected peer in place # of PEER. Alternately you can cycle through all peers, # but this produces redundant output. If you do that, # run the output file through sort -n | uniq before # sharing it. :) if ($_ =~ /^ PEER /) { ($asn_path) = split /:/; $asn_path =~ s/^ //; $asn_path =~ s/, (aggre..*//; @asn_len = split(/ /, $asn_path); $source_asn = $asn_len[$#asn_len]; printf(OUTPUT "%-5.5s %-15s (%s)n", $source_asn, $prefix, $as{$source_asn}); $path_num++; } } } } $cs->close; exit;