#!/usr/local/bin/perl
#filename: /opt/local/perl_scripts/snmpwalk.pl
use SNMP_util;
$MIB1 = shift;
$HOST = shift;
($MIB1) && ($HOST) || die "Usage: $0 MIB_OID HOSTNAME";
(@values) = &snmpwalk("$HOST","$MIB1");
if (@values) { print "Results :$MIB1: :@values:\n"; }
else { warn "No response from host :$HOST:\n"; }
Here's how to run the script:
$ /opt/local/perl_scripts/snmpwalk.pl .1.3.6.1.2.1.2.2.1.2 orarouter1
This command walks down the
.iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifDescr
object, returning information about the interfaces that are on the
router. The results look something like this:
Results :.1.3.6.1.2.1.2.2.1.2: :1:Ethernet0 2:Serial0 3:Serial1:
The output depends on the interfaces on the host or router you are
polling. To give some examples, I've run this script against
some of the machines on my network. Here are the results.
Cisco 7000 router:
Results :.1.3.6.1.2.1.2.2.1.2: :1:Ethernet0/0 2:Ethernet0/1 3:TokenRing1/0
4:TokenRing1/1 5:TokenRing1/2 6:TokenRing1/3 7:Serial2/0 8:Serial2/1
9:Serial2/2 10:Serial2/3 11:Serial2/4 12:Serial2/5 13:Serial2/6 14:Serial2/7
15:FastEthernet3/0 16:FastEthernet3/1 17:TokenRing4/0 18:TokenRing4/1:
Sun workstation:
Results :.1.3.6.1.2.1.2.2.1.2: :1:lo0 2:hme0:
Windows NT PC:
Results :.1.3.6.1.2.1.2.2.1.2: :1:MS TCP Loopback interface
2:PCI2 Token-Ring Network 16/4 Adapter :
APC uninterruptible power supply:
Results :.1.3.6.1.2.1.2.2.1.2: :1:peda: