Hi,<br>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.<br><br>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?<br>
<br>---------<br><br><br>
<br>#!/usr/bin/perl -w<br><br>use Net::SNMP;<br>my $OID_vLanID = '1.3.6.1.2.1.2.2.1.1.';<br><br>my ($session, $error) = Net::SNMP->session(<br> -hostname => 'SWITCH_IP',<br> -community => 'public'<br>
);<br><br>if (!defined $session) {<br> printf "ERROR: %s.\n", $error;<br> exit 1;<br> }<br>$foundLast = 0;<br>$item = 1;<br>while ($foundLast != 1)<br>{<br> $getValue = "$OID_vLanID" . "$item";<br>
$result = $session->get_request(-varbindlist => [ $getValue ],);<br> if (!defined $result)<br> {<br> $item--;<br> printf "ITEM is $item-- -- ERROR: %s.\n", $session->error();<br>
$foundLast = 1;<br> $session->close();<br> }<br> else<br> {<br> $item++;<br> }<br>}<br><br>print "Total: $item\n";<br> $session->close();<br>
<br>exit 0;<br>