Leser: 2
1 Eintrag, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/perl
use strict;
use Net::SNMP qw(:snmp);
my ($session, $error) = Net::SNMP->session(
-version => 'snmpv2c',
-nonblocking => 1,
-hostname => '192.168.1.1',
-community => 'public',
-port => 161
);
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit 1;
}
my $ifTable = '.1.3.6.1.2.1.2.2.1.2';
my $result = $session->get_bulk_request(
-callback => [\&table_cb, {}],
-maxrepetitions => 10,
-varbindlist => [$ifTable]
);
if (!defined($result)) {
printf("ERROR: %s.\n", $session->error);
$session->close;
exit 1;
}
snmp_dispatcher();
sub table_cb
{
my ($session) = @_;
my $table;
if (!defined($session->var_bind_list)) {
printf("ERROR: %s\n", $session->error);
}
else {
my $next;
foreach my $oid (oid_lex_sort(keys %{$session->var_bind_list})) {
if (!oid_base_match($ifTable, $oid)) {
$next = undef;
last;
}
$next = $oid;
$table->{$oid} = $session->var_bind_list->{$oid};
}
foreach my $oid (oid_lex_sort(keys(%{$table}))) {
printf("%s => %s\n", $oid, $table->{$oid});
}
}
}
1 Eintrag, 1 Seite |