1package App::Netdisco::SSHCollector::Platform::IOS;
2
3=head1 NAME
4
5App::Netdisco::SSHCollector::Platform::IOS
6
7=head1 DESCRIPTION
8
9Collect ARP entries from Cisco IOS devices.
10
11=cut
12
13use strict;
14use warnings;
15
16use Dancer ':script';
17use Moo;
18
19=head1 PUBLIC METHODS
20
21=over 4
22
23=item B<arpnip($host, $ssh)>
24
25Retrieve ARP entries from device. C<$host> is the hostname or IP address
26of the device. C<$ssh> is a Net::OpenSSH connection to the device.
27
28Returns a list of hashrefs in the format C<{ mac =E<gt> MACADDR, ip =E<gt> IPADDR }>.
29
30=back
31
32=cut
33
34sub arpnip {
35    my ($self, $hostlabel, $ssh, $args) = @_;
36
37    debug "$hostlabel $$ arpnip()";
38    my @data = $ssh->capture("show ip arp");
39
40    chomp @data;
41    my @arpentries;
42
43    # Internet  172.16.20.15   13   0024.b269.867d  ARPA FastEthernet0/0.1
44    foreach my $line (@data) {
45        next unless $line =~ m/^Internet/;
46        my @fields = split m/\s+/, $line;
47
48        push @arpentries, { mac => $fields[3], ip => $fields[1] };
49    }
50
51    return @arpentries;
52}
53
541;
55