#! /usr/bin/perl -w # netsnmpTinker.pl # ybiC 2001-05-18 13:30 # derived from Net::SNMP example1.pl # online MIB browser at http://www.ibr.cs.tu-bs.de/cgi-bin/sbrowser.cg +i use strict; use Net::SNMP; use Tie::IxHash; my %snmp; ($snmp{session}, $snmp{error}) = Net::SNMP->session( -hostname => shift || 'localhost', -community => shift || 'public', -port => shift || 161, ); tie my %mib, "Tie::IxHash"; %mib = ( # sysDescr => '1.3.6.1.2.1.1.1.0', sysUpTime => '1.3.6.1.2.1.1.3.0', sysContact => '1.3.6.1.2.1.1.4.0', sysName => '1.3.6.1.2.1.1.5.0', sysLocation => '1.3.6.1.2.1.1.6.0', ifNumber => '1.3.6.1.2.1.2.1.0', cdpAddress => '1.3.6.1.4.1.9.9.23.1.2.1.1.4', cdpDeviceID => '1.3.6.1.4.1.9.9.23.1.2.1.1.6', cdpHWtype => '1.3.6.1.4.1.9.9.23.1.2.1.1.8', ); unless (defined($snmp{session})) { printf(" Error: %s.\n", $snmp{error}); exit 1; } printf("\n Host = %s\n", $snmp{session} ->hostname()); for(keys %mib) { if (defined($snmp{response} = $snmp{session}->get_request($mib{$_}) +)) { printf(" $_ = %s\n", $snmp{response}->{$mib{$_}}); } else { print " $_ = not responding\n"} } $snmp{session}->close(); print "\n"; exit 0;
In reply to Re:(2) uninit value, Tie::IxHash, Net::SNMP (thanks, working snippet)
by ybiC
in thread uninitialized value with Tie::IxHash and Net::SNMP
by ybiC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |