#! /usr/bin/perl -w # netsnmpt.pl use strict; use Net::SNMP(qw(snmp_event_loop oid_lex_sort)); my @targets = @ARGV; my @oid = ( '.1.3.6.1.2.1.2.2.1.1', '.1.3.6.1.2.1.31.1.1.1.1', '.1.3.6.1.2.1.2.2.1.7', '.1.3.6.1.2.1.2.2.1.8', ); # ifIndex # ifName # ifAdminStatus # ifOperStatus my ($session, $error, $response); for my $target(@targets) { ($session, $error) = Net::SNMP -> session( -hostname => $target, -community => 'public', ); print($session -> hostname(), "\n"); for my $oid(@oid) { if (defined($response = $session -> get_table($oid))) { for my $value(oid_lex_sort(keys(%{$response}))) { print($response -> {$value}, "\n"); } } else { print($session -> error(), "\n"); } } }