[pgh-pm] perl net snmp
G.Pitman
gpitman at gmail.com
Fri Jan 22 07:44:48 PST 2010
Hi,
I used to use perl a bit but I am very rusty. I am trying to walk the
ifIndex portion of a cisco switch so that I can either get the last index
number or build an array of index numbers to use for queries.
I have tried using a get_request in a loop until I get an error but there is
a break in list. When I do an snmpwalk I see index numbers from 1-105 and
154-224 with the break in the middle so my script stops at 105 indicating
that it is the last. If I use get_next_request it does not error out. Can
anyone guide my failing logic?
---------
#!/usr/bin/perl -w
use Net::SNMP;
my $OID_vLanID = '1.3.6.1.2.1.2.2.1.1.';
my ($session, $error) = Net::SNMP->session(
-hostname => 'SWITCH_IP',
-community => 'public'
);
if (!defined $session) {
printf "ERROR: %s.\n", $error;
exit 1;
}
$foundLast = 0;
$item = 1;
while ($foundLast != 1)
{
$getValue = "$OID_vLanID" . "$item";
$result = $session->get_request(-varbindlist => [ $getValue ],);
if (!defined $result)
{
$item--;
printf "ITEM is $item-- -- ERROR: %s.\n", $session->error();
$foundLast = 1;
$session->close();
}
else
{
$item++;
}
}
print "Total: $item\n";
$session->close();
exit 0;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/pgh-pm/attachments/20100122/56a14bd7/attachment.html>
More information about the pgh-pm
mailing list