line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SNMP::BridgeQuery; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
626
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
108
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
@EXPORT = qw(queryfdb); |
10
|
|
|
|
|
|
|
@EXPORT_OK = qw(querymacs queryports queryat); |
11
|
|
|
|
|
|
|
$VERSION = 0.61; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
1396
|
use Net::SNMP; |
|
1
|
|
|
|
|
204883
|
|
|
1
|
|
|
|
|
925
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my ($session); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub connect { |
18
|
0
|
|
|
0
|
0
|
|
my %cla = @_; |
19
|
0
|
0
|
|
|
|
|
$cla{comm} = "public" unless exists $cla{comm}; |
20
|
0
|
|
|
|
|
|
$session = Net::SNMP->session(-hostname => $cla{host}, |
21
|
|
|
|
|
|
|
-community => $cla{comm}, |
22
|
|
|
|
|
|
|
-translate => [-octetstring => 0x0], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub queryat { |
27
|
0
|
|
|
0
|
0
|
|
my ($key, $newkey, %final); |
28
|
0
|
|
|
|
|
|
&connect(@_); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $ifoid = '1.3.6.1.2.1.3.1.1.1'; |
31
|
0
|
|
|
|
|
|
my $ifref = $session->get_table($ifoid); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if ($session->error) { |
34
|
0
|
|
|
|
|
|
return {error => "true"}; |
35
|
0
|
|
|
|
|
|
exit 1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $physoid = '1.3.6.1.2.1.3.1.1.2'; |
39
|
0
|
|
|
|
|
|
my $physref = $session->get_table($physoid); |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ($session->error) { |
42
|
0
|
|
|
|
|
|
return {error => "true"}; |
43
|
0
|
|
|
|
|
|
exit 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $addroid = '1.3.6.1.2.1.3.1.1.3'; |
47
|
0
|
|
|
|
|
|
my $addrref = $session->get_table($addroid); |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($session->error) { |
50
|
0
|
|
|
|
|
|
return {error => "true"}; |
51
|
0
|
|
|
|
|
|
exit 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
foreach $key (keys %{$physref}) { |
|
0
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$physref->{$key} = unpack('H12', $physref->{$key}); |
56
|
0
|
0
|
|
|
|
|
next if (length($physref->{$key}) < 12); |
57
|
0
|
|
|
|
|
|
($newkey = $key) =~ s/$physoid//; |
58
|
0
|
|
|
|
|
|
$final{$physref->{$key}} = |
59
|
|
|
|
|
|
|
$addrref->{$addroid . $newkey} . "|" . |
60
|
|
|
|
|
|
|
$ifref->{$ifoid . $newkey}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return \%final; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub queryfdb { |
67
|
0
|
|
|
0
|
0
|
|
my ($key, $newkey, %port, %final); |
68
|
0
|
|
|
|
|
|
&connect(@_); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $macoid = '1.3.6.1.2.1.17.4.3.1.1'; |
71
|
0
|
|
|
|
|
|
my $macref = $session->get_table($macoid); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ($session->error) { |
74
|
0
|
|
|
|
|
|
return {error => "true"}; |
75
|
0
|
|
|
|
|
|
exit 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $portoid = '1.3.6.1.2.1.17.4.3.1.2'; |
79
|
0
|
|
|
|
|
|
my $portref = $session->get_table($portoid); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ($session->error) { |
82
|
0
|
|
|
|
|
|
return {error => "true"}; |
83
|
0
|
|
|
|
|
|
exit 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
foreach $key (keys %{$portref}) { |
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
($newkey = $key) =~ s/$portoid\.//; |
88
|
0
|
|
|
|
|
|
$port{$newkey} = $portref->{$key}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
foreach $key (keys %{$macref}) { |
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$macref->{$key} = unpack('H12', $macref->{$key}); |
93
|
0
|
0
|
|
|
|
|
next if (length($macref->{$key}) < 12); |
94
|
0
|
|
|
|
|
|
($newkey = $key) =~ s/$macoid\.//; |
95
|
0
|
|
|
|
|
|
$final{$macref->{$key}} = $port{$newkey} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return \%final; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub querymacs { |
102
|
0
|
|
|
0
|
0
|
|
my ($key, $newkey, %mac); |
103
|
0
|
|
|
|
|
|
&connect(@_); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $macoid = '1.3.6.1.2.1.17.4.3.1.1'; |
106
|
0
|
|
|
|
|
|
my $macref = $session->get_table($macoid); |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if ($session->error) { |
109
|
0
|
|
|
|
|
|
return {error => "true"}; |
110
|
0
|
|
|
|
|
|
exit 1; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
foreach $key (keys %{$macref}) { |
|
0
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
($newkey = $key ) =~ s/$macoid\.//; |
115
|
0
|
|
|
|
|
|
$macref->{$key} = unpack('H12', $macref->{$key}); |
116
|
0
|
|
|
|
|
|
$mac{$newkey} = sprintf("%12s", $macref->{$key}); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return \%mac; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub queryports { |
123
|
0
|
|
|
0
|
0
|
|
my ($key, $newkey, %port); |
124
|
0
|
|
|
|
|
|
&connect(@_); |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $portoid = '1.3.6.1.2.1.17.4.3.1.2'; |
127
|
0
|
|
|
|
|
|
my $portref = $session->get_table($portoid); |
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
if ($session->error) { |
130
|
0
|
|
|
|
|
|
return {error => "true"}; |
131
|
0
|
|
|
|
|
|
exit 1; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
foreach $key (keys %{$portref}) { |
|
0
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
($newkey = $key ) =~ s/$portoid\.//; |
136
|
0
|
|
|
|
|
|
$port{$newkey} = $portref->{$key}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return \%port; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |