sub
arpnip {
my
(
$self
,
$hostlabel
,
$ssh
,
$args
) =
@_
;
debug
"$hostlabel $$ arpnip()"
;
my
(
$pty
,
$pid
) =
$ssh
->open2pty or
die
"unable to run remote command"
;
my
$expect
= Expect->init(
$pty
);
my
(
$pos
,
$error
,
$match
,
$before
,
$after
);
my
$prompt
=
qr/\$/
;
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(10, -re,
$prompt
);
my
$command
= (
$args
->{arp_command} ||
'arp'
);
$expect
->
send
(
"$command -n | tail -n +2\n"
);
(
$pos
,
$error
,
$match
,
$before
,
$after
) =
$expect
->expect(5, -re,
$prompt
);
my
@arpentries
= ();
my
@lines
=
split
(m/\n/,
$before
);
my
$linereg
=
qr/([0-9\.]+)\s+ether\s+([a-fA-F0-9:]+)/
;
foreach
my
$line
(
@lines
) {
if
(
$line
=~
$linereg
) {
my
(
$ip
,
$mac
) = ($1, $2);
push
@arpentries
, {
mac
=>
$mac
,
ip
=>
$ip
};
}
}
$expect
->
send
(
"exit\n"
);
$expect
->soft_close();
return
@arpentries
;
}
1;