line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::IP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
75483
|
use strict; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
38
|
|
9
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
707
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
92222
|
|
|
1
|
|
|
|
|
388
|
|
12
|
1
|
|
|
1
|
|
532
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
833
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _ipOID { |
23
|
0
|
|
|
0
|
|
0
|
return '.1.3.6.1.2.1.4'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub ipOIDs { |
27
|
3
|
|
|
3
|
1
|
17
|
return qw( |
28
|
|
|
|
|
|
|
Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors |
29
|
|
|
|
|
|
|
ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests |
30
|
|
|
|
|
|
|
OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs |
31
|
|
|
|
|
|
|
ReasmFails FragOKs FragFails FragCreates |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub addrOIDs { |
36
|
2
|
|
|
2
|
1
|
4
|
return qw(Addr IfIndex NetMask BcastAddr ReasmMaxSize); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub routeOIDs { |
40
|
2
|
|
|
2
|
1
|
5
|
return qw( |
41
|
|
|
|
|
|
|
Dest IfIndex Metric1 Metric2 Metric3 |
42
|
|
|
|
|
|
|
Metric4 NextHop Type Proto Age |
43
|
|
|
|
|
|
|
Mask Metric5 Info |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ip_info { |
48
|
0
|
|
|
0
|
1
|
|
my ( $self, $arg ) = @_; |
49
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my %ret; |
54
|
0
|
|
|
|
|
|
my @IPKEYS = ipOIDs(); |
55
|
0
|
|
|
|
|
|
for my $oid ( 0 .. $#IPKEYS ) { |
56
|
0
|
|
|
|
|
|
$ret{$IPKEYS[$oid]} |
57
|
|
|
|
|
|
|
= Cisco::SNMP::_snmpwalk( $session, _ipOID() . '.' . ( $oid + 1 ) ); |
58
|
0
|
0
|
|
|
|
|
if ( not defined $ret{$IPKEYS[$oid]} ) { |
59
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get IP `$IPKEYS[$oid]' info"; |
60
|
0
|
|
|
|
|
|
return undef; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my %ForType = ( |
65
|
|
|
|
|
|
|
1 => 'forwarding', |
66
|
|
|
|
|
|
|
2 => 'not-forwarding' |
67
|
|
|
|
|
|
|
); |
68
|
0
|
|
|
|
|
|
my @IpInfo; |
69
|
0
|
|
|
|
|
|
for my $ip ( 0 .. $#{$ret{$IPKEYS[0]}} ) { |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my %IpInfoHash; |
71
|
0
|
|
|
|
|
|
for ( 0 .. $#IPKEYS ) { |
72
|
0
|
0
|
|
|
|
|
if ( $_ == 0 ) { |
73
|
|
|
|
|
|
|
$IpInfoHash{$IPKEYS[$_]} |
74
|
|
|
|
|
|
|
= exists( $ForType{$ret{$IPKEYS[$_]}->[$ip]} ) |
75
|
|
|
|
|
|
|
? $ForType{$ret{$IPKEYS[$_]}->[$ip]} |
76
|
0
|
0
|
|
|
|
|
: $ret{$IPKEYS[$_]}->[$ip]; |
77
|
|
|
|
|
|
|
} else { |
78
|
0
|
|
|
|
|
|
$IpInfoHash{$IPKEYS[$_]} = $ret{$IPKEYS[$_]}->[$ip]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
push @IpInfo, \%IpInfoHash; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
return bless \@IpInfo, $class; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
for ( ipOIDs() ) { |
87
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1( 'ip', $_ ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub ip_forwardingOn { |
91
|
0
|
|
|
0
|
1
|
|
return set_ipForwarding( shift, 1 ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub ip_forwardingOff { |
95
|
0
|
|
|
0
|
1
|
|
return set_ipForwarding( shift, 2 ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub addr_info { |
99
|
0
|
|
|
0
|
1
|
|
my ( $self, $arg ) = @_; |
100
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my %ret; |
105
|
0
|
|
|
|
|
|
my @ADDRKEYS = addrOIDs(); |
106
|
0
|
|
|
|
|
|
for my $oid ( 0 .. $#ADDRKEYS ) { |
107
|
0
|
|
|
|
|
|
$ret{$ADDRKEYS[$oid]} = Cisco::SNMP::_snmpwalk( $session, |
108
|
|
|
|
|
|
|
_ipOID() . '.20.1.' . ( $oid + 1 ) ); |
109
|
0
|
0
|
|
|
|
|
if ( not defined $ret{$ADDRKEYS[$oid]} ) { |
110
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR |
111
|
|
|
|
|
|
|
= "Cannot get address `$ADDRKEYS[$oid]' info"; |
112
|
0
|
|
|
|
|
|
return undef; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my %AddrInfo; |
117
|
0
|
|
|
|
|
|
for my $ip ( 0 .. $#{$ret{$ADDRKEYS[0]}} ) { |
|
0
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my %AddrInfoHash; |
119
|
0
|
|
|
|
|
|
for ( 0 .. $#ADDRKEYS ) { |
120
|
0
|
|
|
|
|
|
$AddrInfoHash{$ADDRKEYS[$_]} = $ret{$ADDRKEYS[$_]}->[$ip]; |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
push @{$AddrInfo{$ret{$ADDRKEYS[1]}->[$ip]}}, \%AddrInfoHash; |
|
0
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
return bless \%AddrInfo, $class; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
for ( addrOIDs() ) { |
128
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_2( 'if', 'addr', $_ ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub route_info { |
132
|
0
|
|
|
0
|
1
|
|
my ( $self, $arg ) = @_; |
133
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my %ret; |
138
|
0
|
|
|
|
|
|
my @ROUTEKEYS = routeOIDs(); |
139
|
0
|
|
|
|
|
|
for my $oid ( 0 .. $#ROUTEKEYS ) { |
140
|
0
|
|
|
|
|
|
$ret{$ROUTEKEYS[$oid]} = Cisco::SNMP::_snmpwalk( $session, |
141
|
|
|
|
|
|
|
_ipOID() . '.21.1.' . ( $oid + 1 ) ); |
142
|
0
|
0
|
|
|
|
|
if ( not defined $ret{$ROUTEKEYS[$oid]} ) { |
143
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR |
144
|
|
|
|
|
|
|
= "Cannot get route `$ROUTEKEYS[$oid]' info"; |
145
|
0
|
|
|
|
|
|
return undef; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
my %RouteType = ( |
150
|
|
|
|
|
|
|
1 => 'other', |
151
|
|
|
|
|
|
|
2 => 'invalid', |
152
|
|
|
|
|
|
|
3 => 'direct', |
153
|
|
|
|
|
|
|
4 => 'indirect' |
154
|
|
|
|
|
|
|
); |
155
|
0
|
|
|
|
|
|
my %RouteProto = ( |
156
|
|
|
|
|
|
|
1 => 'other', |
157
|
|
|
|
|
|
|
2 => 'local', |
158
|
|
|
|
|
|
|
3 => 'netmgmt', |
159
|
|
|
|
|
|
|
4 => 'icmp', |
160
|
|
|
|
|
|
|
5 => 'egp', |
161
|
|
|
|
|
|
|
6 => 'ggp', |
162
|
|
|
|
|
|
|
7 => 'hello', |
163
|
|
|
|
|
|
|
8 => 'rip', |
164
|
|
|
|
|
|
|
9 => 'is-is', |
165
|
|
|
|
|
|
|
10 => 'es-is', |
166
|
|
|
|
|
|
|
11 => 'ciscoIgrp', |
167
|
|
|
|
|
|
|
12 => 'bbnSpfIgp', |
168
|
|
|
|
|
|
|
13 => 'ospf', |
169
|
|
|
|
|
|
|
14 => 'bgp' |
170
|
|
|
|
|
|
|
); |
171
|
0
|
|
|
|
|
|
my @RouteInfo; |
172
|
0
|
|
|
|
|
|
for my $ip ( 0 .. $#{$ret{$ROUTEKEYS[0]}} ) { |
|
0
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
my %RouteInfoHash; |
174
|
0
|
|
|
|
|
|
for ( 0 .. $#ROUTEKEYS ) { |
175
|
0
|
0
|
|
|
|
|
if ( $_ == 8 ) { |
|
|
0
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$RouteInfoHash{$ROUTEKEYS[$_]} |
177
|
|
|
|
|
|
|
= exists( $RouteType{$ret{$ROUTEKEYS[$_]}->[$ip]} ) |
178
|
|
|
|
|
|
|
? $RouteType{$ret{$ROUTEKEYS[$_]}->[$ip]} |
179
|
0
|
0
|
|
|
|
|
: $ret{$ROUTEKEYS[$_]}->[$ip]; |
180
|
|
|
|
|
|
|
} elsif ( $_ == 9 ) { |
181
|
|
|
|
|
|
|
$RouteInfoHash{$ROUTEKEYS[$_]} |
182
|
|
|
|
|
|
|
= exists( $RouteProto{$ret{$ROUTEKEYS[$_]}->[$ip]} ) |
183
|
|
|
|
|
|
|
? $RouteProto{$ret{$ROUTEKEYS[$_]}->[$ip]} |
184
|
0
|
0
|
|
|
|
|
: $ret{$ROUTEKEYS[$_]}->[$ip]; |
185
|
|
|
|
|
|
|
} else { |
186
|
0
|
|
|
|
|
|
$RouteInfoHash{$ROUTEKEYS[$_]} = $ret{$ROUTEKEYS[$_]}->[$ip]; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
|
push @RouteInfo, \%RouteInfoHash; |
190
|
|
|
|
|
|
|
} |
191
|
0
|
|
|
|
|
|
return bless \@RouteInfo, $class; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
for ( routeOIDs() ) { |
195
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1( 'route', $_ ); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
1
|
|
|
1
|
|
10
|
no strict 'refs'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
470
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# get_ direct |
201
|
|
|
|
|
|
|
my @OIDS = ipOIDs(); |
202
|
|
|
|
|
|
|
for my $o ( 0 .. $#OIDS ) { |
203
|
|
|
|
|
|
|
*{"get_ip" . $OIDS[$o]} = sub { |
204
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
my $s = $self->session; |
207
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
208
|
|
|
|
|
|
|
varbindlist => [_ipOID() . '.' . ( $o + 1 ) . '.0'] ); |
209
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.' . ( $o + 1 ) . '.0'}; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
@OIDS = addrOIDs(); |
214
|
|
|
|
|
|
|
for my $o ( 0 .. $#OIDS ) { |
215
|
|
|
|
|
|
|
*{"get_addr" . $OIDS[$o]} = sub { |
216
|
0
|
|
|
0
|
|
|
my $self = shift; |
217
|
0
|
|
|
|
|
|
my ($val) = @_; |
218
|
|
|
|
|
|
|
|
219
|
0
|
0
|
|
|
|
|
if ( not defined $val ) { $val = '0.0.0.0' } |
|
0
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
my $s = $self->session; |
221
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
222
|
|
|
|
|
|
|
varbindlist => [_ipOID() . '.20.1.' . ( $o + 1 ) . '.' . $val] ); |
223
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.20.1.' . ( $o + 1 ) . '.' . $val}; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
@OIDS = routeOIDs(); |
228
|
|
|
|
|
|
|
for my $o ( 0 .. $#OIDS ) { |
229
|
|
|
|
|
|
|
*{"get_route" . $OIDS[$o]} = sub { |
230
|
0
|
|
|
0
|
|
|
my $self = shift; |
231
|
0
|
|
|
|
|
|
my ($val) = @_; |
232
|
|
|
|
|
|
|
|
233
|
0
|
0
|
|
|
|
|
if ( not defined $val ) { $val = '0.0.0.0' } |
|
0
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
my $s = $self->session; |
235
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
236
|
|
|
|
|
|
|
varbindlist => [_ipOID() . '.21.1.' . ( $o + 1 ) . '.' . $val] ); |
237
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.21.1.' . ( $o + 1 ) . '.' . $val}; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# set_ direct |
242
|
|
|
|
|
|
|
@OIDS = ipOIDs(); |
243
|
|
|
|
|
|
|
for my $o ( 0 .. 1 ) { |
244
|
|
|
|
|
|
|
my $def = 1; |
245
|
|
|
|
|
|
|
if ( $o == 1 ) { $def = 255 } |
246
|
|
|
|
|
|
|
*{"set_ip" . $OIDS[$o]} = sub { |
247
|
0
|
|
|
0
|
|
|
my $self = shift; |
248
|
0
|
|
|
|
|
|
my ($val) = @_; |
249
|
0
|
0
|
|
|
|
|
if ( not defined $val ) { $val = $def } |
|
0
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $s = $self->session; |
251
|
0
|
|
|
|
|
|
my $r = $s->set_request( _ipOID() . '.' . ( $o + 1 ) . '.0', INTEGER, |
252
|
|
|
|
|
|
|
$val ); |
253
|
0
|
0
|
|
|
|
|
if ( not defined $r ) { |
254
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = $s->error; |
255
|
0
|
|
|
|
|
|
return; |
256
|
|
|
|
|
|
|
} else { |
257
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.' . ( $o + 1 ) . '.0'}; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
################################################## |
263
|
|
|
|
|
|
|
# End Public Module |
264
|
|
|
|
|
|
|
################################################## |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
1; |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
__END__ |