sub
arpnip {
my
(
$self
,
$hostlabel
,
$ssh
,
$args
) =
@_
;
debug
"$hostlabel arpnip() - Starting ARP collection for Aruba Controller"
;
my
(
$pty
,
$pid
) =
$ssh
->open2pty;
unless
(
$pty
) {
debug
"unable to run remote command [$hostlabel] "
.
$ssh
->error;
return
();
}
my
$expect
= Expect->init(
$pty
);
my
$prompt
=
qr/#/
; # Adjust to match the Aruba controller prompt
$expect
->expect(10, -re,
$prompt
);
$expect
->
send
(
"no paging\n"
);
$expect
->expect(10, -re,
$prompt
);
$expect
->
send
(
"show arp\n"
);
my
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
my
@data
=
split
"\n"
,
$before
;
my
@arpentries
;
foreach
my
$line
(
@data
) {
if
(
$line
=~ /(\d+\.\d+\.\d+\.\d+)\s+([\da-f:]+)\s+(vlan\d+)/) {
push
@arpentries
, {
ip
=> $1,
mac
=> $2,
port
=> $3 };
debug
"$hostlabel - Parsed ARP entry: IP=$1, MAC=$2, Port=$3"
;
}
}
debug
"$hostlabel - Parsed "
.
scalar
(
@arpentries
) .
" ARP entries"
;
return
@arpentries
;
}
1;