Skip to Content
Cisco IOS Cookbook, 2nd Edition
book

Cisco IOS Cookbook, 2nd Edition

by Kevin Dooley, Ian Brown
December 2006
Intermediate to advanced
1188 pages
72h 8m
English
O'Reilly Media, Inc.
Content preview from Cisco IOS Cookbook, 2nd Edition

Generating a Report of Routing Table Information

Problem

You need to extract the IP routing table from one of your routers.

Solution

The script in Example 2-2, rt.pl, uses SNMP to extract the routing table from a specified router, and displays this information to standard output (STDOUT). The script expects to find a hostname or IP address of a router on the command line.

Example 2-2. rt.pl

#!/usr/bin/perl # # rt.pl -- a script to extract the routing table # from a router. # #Set behavior $snmpro="ORARO"; # $x=0; $snmpwalk="/usr/local/bin/snmpwalk -v 1 -c $snmpro"; $snmpget="/usr/local/bin/snmpget -v 1 -c $snmpro"; chomp ($rtr=$ARGV[0]); if ( $rtr eq "" ) {die "$0: Must specify a router\n"}; print "Destination\tMask\t\tNexthop"; print "\t\t Proto\tInterface\n"; @iftable=\Q$snmpwalk $rtr ifDescr\Q; for $ifnum (@iftable) { chomp (($intno, $intname) = split (/ = /, $ifnum)); $intno=~s/.*ifDescr\.//; $intname=~s/"//gi; $int{$intno}=$intname; } @ipRouteDest=\Q$snmpwalk $rtr ipRouteDest\Q; @ipRouteMask=\Q$snmpwalk $rtr ipRouteMask\Q; @ipRouteNextHop=\Q$snmpwalk $rtr ipRouteNextHop\Q; @ipRouteProto=\Q$snmpwalk $rtr ipRouteProto\Q; @ipRouteIfIndex=\Q$snmpwalk $rtr ipRouteIfIndex\Q; #@ipRouteMetric1=\Q$snmpwalk $rtr ipRouteMetric1\Q; for $intnum (@ipRouteIfIndex) { chomp (($foo, $int) = split (/= /, $intnum)); chomp (($foo, $dest) = split (/: /, @ipRouteDest[$x])); chomp (($foo, $mask) = split (/: /, @ipRouteMask[$x])); chomp (($foo, $nhop) = split (/: /, @ipRouteNextHop[$x])); chomp (($foo, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

IP Routing on Cisco IOS, IOS XE, and IOS XR: An Essential Guide to Understanding and Implementing IP Routing Protocols

IP Routing on Cisco IOS, IOS XE, and IOS XR: An Essential Guide to Understanding and Implementing IP Routing Protocols

Brad Edgeworth, Aaron Foss, Ramiro Garza Rios
Cisco Software-Defined Access

Cisco Software-Defined Access

Srilatha Vemula, Jason Gooley, Roddie Hasan

Publisher Resources

ISBN: 0596527225Supplemental ContentErrata Page