in reply to Reading IP from a file and SNMP
Probably the simplest module to work with for getting at arbitrary MIBs is Net::SNMP - the following example (hacked from the code in my Net::SNMP::Interfaces ) walks the ifTable for hosts who's IP are specified in the file ipfile.txt (one per line) and and prints the description of the interface:
use Net::SNMP; use strict; use warnings; + open IPFILE, "ipfile.txt" or die "Can't get IPs - $!\n"; + my $community = 'public'; my $ifIndex = '1.3.6.1.2.1.2.2.1.1'; my $ifDescr = '1.3.6.1.2.1.2.2.1.2'; + while ( my $ip = <IPFILE> ) { chomp $ip; + my ( $session, $error ) = Net::SNMP->session( -hostname => $ip, -community => $community, -port => 161 ); my $response; + if ( defined( $response = $session->get_table($ifIndex) ) ) { foreach my $index ( values %{$response} ) { my $this_desc = "$ifDescr.$index"; my $description; if ( defined( $description = $session->get_request($this_d +esc) ) ) { print values %{$description}, "\n"; } } + } + $session->close(); }
Hope that helps
/J\
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading IP from a file and SNMP
by theroninwins (Friar) on Aug 27, 2004 at 07:33 UTC | |
by gellyfish (Monsignor) on Aug 27, 2004 at 08:04 UTC | |
by theroninwins (Friar) on Aug 27, 2004 at 11:54 UTC |