|
RFC1795 (IS/IT--Management) |
24 Apr 12 12:34 |
Hi all I'm trying to understand why this snmp script is not working, not sure if its the actual script that is the issue as I'm not clued up in perl really (or snmp for that matter). Figured as I'm trying to do this using SNMP this might be the best place to ask. Original code is grabbed and adjusted from here with Feherke assistance: http://fengnet.com/book/cisco.ios.cookbook.2nd/I_0596527225_CHP_2_SECT_19.htmlCODE#!/usr/bin/perl # # rt.pl -- a script to extract the routing table # from a router. # #Set behavior $snmpro='private=string'; # $x=0; $snmpwalk="/usr/bin/snmpwalk -v 1 -c $snmpro"; #$snmpget="/usr/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=`$snmpwalk $rtr ifDescr`; #@iftable=qq{$snmpwalk $rtr ifDescr}; for $ifnum (@iftable) { chomp (($intno, $intname) = split (/ = /, $ifnum)); $intno=~s/.*ifDescr\.//; $intname=~s/"//gi; $int{$intno}=$intname; }
@ipRouteDest=`$snmpwalk $rtr ipRouteDest`; @ipRouteDest=`$snmpwalk $rtr ipRouteDest`; @ipRouteMask=`$snmpwalk $rtr ipRouteMask`; @ipRouteNextHop=`$snmpwalk $rtr ipRouteNextHop`; @ipRouteProto=`$snmpwalk $rtr ipRouteProto`; @ipRouteIfIndex=`$snmpwalk $rtr ipRouteIfIndex`; 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, $prot) = split (/= /, @ipRouteProto[$x])); #chomp (($foo, $metr) = split (/= /, @ipRouteMetric1[$x])); $int1 = $int{$int}; if ($int1 eq '') {$int1="Local"}; $prot=~s/\(.*//; $prot=~s/ciscoIgrp/\(e\)igrp/; printf ("%-15s %-15s %-15s %7s %-25s\n",$dest, $mask, $nhop, $prot, $int1); $x++ } Its supposed to output data like this: CODEFreebsd% ./rt.pl toronto Destination Mask Nexthop Proto Interface 10.1.1.0 255.255.255.252 172.25.1.5 ospf Ethernet0 10.2.2.2 255.255.255.255 172.25.1.5 ospf Ethernet0 172.16.2.0 255.255.255.0 172.25.1.5 ospf Ethernet0 172.20.0.0 255.255.0.0 172.25.1.5 local Local 172.20.1.0 255.255.255.252 172.25.1.5 ospf Ethernet0 172.20.10.0 255.255.255.0 172.25.1.5 ospf Ethernet0 172.20.100.1 255.255.255.255 172.25.1.5 ospf Ethernet0 172.22.0.0 255.255.0.0 172.25.1.5 (e)igrp Ethernet0 172.22.1.0 255.255.255.0 172.25.1.5 ospf Ethernet0 172.25.1.0 255.255.255.0 172.25.1.7 local Ethernet0 172.25.2.0 255.255.255.252 172.25.1.5 (e)igrp Ethernet0 172.25.25.1 255.255.255.255 172.25.1.5 (e)igrp Ethernet0 172.25.25.6 255.255.255.255 172.25.25.6 local Loopback0 172.25.26.4 255.255.255.252 172.25.1.5 (e)igrp Ethernet0 172.25.26.5 255.255.255.255 172.25.1.5 ospf Ethernet0 Freebsd% But when I run it I just get the headers and nothing else. (Script completes and drops me to prompt once done.) Is there a better way to do this perhaps? Or should I head beck to the Perl forum hehe |
|