line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::ARP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
48955
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
504
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
56975
|
|
|
1
|
|
|
|
|
211
|
|
12
|
1
|
|
|
1
|
|
338
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
579
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _arpOID { |
23
|
0
|
|
|
0
|
|
0
|
return '.1.3.6.1.2.1.4.22.1'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub arpOIDs { |
27
|
2
|
|
|
2
|
1
|
6
|
return qw(IfIndex PhysAddress NetAddress Type); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub arp_clear { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my ( $idx, $ip ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ( not defined $idx ) { |
|
|
0
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "ifIndex required"; |
36
|
0
|
|
|
|
|
|
return undef; |
37
|
|
|
|
|
|
|
} elsif ( $idx !~ /^\d+$/ ) { |
38
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid ifIndex `$idx'"; |
39
|
0
|
|
|
|
|
|
return undef; |
40
|
|
|
|
|
|
|
} |
41
|
0
|
0
|
|
|
|
|
if ( not defined $ip ) { |
|
|
0
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "IP address required"; |
43
|
0
|
|
|
|
|
|
return undef; |
44
|
|
|
|
|
|
|
} elsif ( $ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ ) { |
45
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid IP Address `$ip'"; |
46
|
0
|
|
|
|
|
|
return undef; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $s = $self->session; |
50
|
0
|
|
|
|
|
|
my $r = $s->set_request( _arpOID() . ".4.$idx.$ip", INTEGER, 2 ); |
51
|
0
|
0
|
|
|
|
|
if ( not defined $r ) { |
52
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = $s->error; |
53
|
0
|
|
|
|
|
|
return undef; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return $r->{_arpOID() . ".4.$idx.$ip"}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub arp_info { |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my %ret; |
65
|
0
|
|
|
|
|
|
my @ARPKEYS = arpOIDs(); |
66
|
0
|
|
|
|
|
|
for my $oid ( 0 .. $#ARPKEYS ) { |
67
|
0
|
|
|
|
|
|
$ret{$ARPKEYS[$oid]} = Cisco::SNMP::_snmpwalk( $session, |
68
|
|
|
|
|
|
|
_arpOID() . '.' . ( $oid + 1 ) ); |
69
|
0
|
0
|
|
|
|
|
if ( not defined $ret{$ARPKEYS[$oid]} ) { |
70
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get ARP `$ARPKEYS[$oid]' info"; |
71
|
0
|
|
|
|
|
|
return undef; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my %ArpType = ( |
76
|
|
|
|
|
|
|
1 => 'OTHER', |
77
|
|
|
|
|
|
|
2 => 'INVALID', |
78
|
|
|
|
|
|
|
3 => 'DYNAMIC', |
79
|
|
|
|
|
|
|
4 => 'STATIC' |
80
|
|
|
|
|
|
|
); |
81
|
0
|
|
|
|
|
|
my @ArpInfo; |
82
|
0
|
|
|
|
|
|
for my $arp ( 0 .. $#{$ret{$ARPKEYS[0]}} ) { |
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my %ArpInfoHash; |
84
|
0
|
|
|
|
|
|
for ( 0 .. $#ARPKEYS ) { |
85
|
0
|
0
|
|
|
|
|
if ( $_ == 1 ) { |
|
|
0
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$ArpInfoHash{$ARPKEYS[$_]} |
87
|
|
|
|
|
|
|
= ( $ret{$ARPKEYS[$_]}->[$arp] =~ /^\0/ ) |
88
|
|
|
|
|
|
|
? unpack( 'H12', $ret{$ARPKEYS[$_]}->[$arp] ) |
89
|
|
|
|
|
|
|
: ( ( $ret{$ARPKEYS[$_]}->[$arp] =~ /^0x/ ) |
90
|
|
|
|
|
|
|
? substr( $ret{$ARPKEYS[$_]}->[$arp], 2 ) |
91
|
0
|
0
|
|
|
|
|
: $ret{$ARPKEYS[$_]}->[$arp] ); |
|
|
0
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} elsif ( $_ == 3 ) { |
93
|
|
|
|
|
|
|
$ArpInfoHash{$ARPKEYS[$_]} |
94
|
|
|
|
|
|
|
= exists( $ArpType{$ret{$ARPKEYS[$_]}->[$arp]} ) |
95
|
|
|
|
|
|
|
? $ArpType{$ret{$ARPKEYS[$_]}->[$arp]} |
96
|
0
|
0
|
|
|
|
|
: $ret{$ARPKEYS[$_]}->[$arp]; |
97
|
|
|
|
|
|
|
} else { |
98
|
0
|
|
|
|
|
|
$ArpInfoHash{$ARPKEYS[$_]} = $ret{$ARPKEYS[$_]}->[$arp]; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
|
push @ArpInfo, \%ArpInfoHash; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
return bless \@ArpInfo, $class; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
for ( arpOIDs() ) { |
107
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1( 'arp', $_ ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
1
|
|
10
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
213
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# get_ direct |
113
|
|
|
|
|
|
|
my @OIDS = arpOIDs(); |
114
|
|
|
|
|
|
|
for my $o ( 0 .. $#OIDS ) { |
115
|
|
|
|
|
|
|
*{"get_arp" . $OIDS[$o]} = sub { |
116
|
0
|
|
|
0
|
|
|
my $self = shift; |
117
|
0
|
|
|
|
|
|
my ( $val1, $val2 ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if ( not defined $val1 ) { $val1 = 1 } |
|
0
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if ( not defined $val2 ) { $val2 = '1.1.1.1' } |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $s = $self->session; |
122
|
0
|
|
|
|
|
|
my $r = $s->get_request( varbindlist => |
123
|
|
|
|
|
|
|
[_arpOID() . '.' . ( $o + 1 ) . '.' . "$val1.$val2"] ); |
124
|
0
|
|
|
|
|
|
return $r->{_arpOID() . '.' . ( $o + 1 ) . '.' . "$val1.$val2"}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
################################################## |
129
|
|
|
|
|
|
|
# End Public Module |
130
|
|
|
|
|
|
|
################################################## |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |