in reply to How to use "$ssh->before()"

I want to know peer ip is alive or not.

If you know the peer IP addresses, use Net::Ping module to ping set of IP addresses,

Ex,

use Net::Ping; my $p = Net::Ping->new("icmp"); my @host_array = (IP1,IP2,IP3...); foreach $host (@host_array) { print "$host is "; print "NOT " unless $p->ping($host, 2); print "reachable.\n"; sleep(1); } $p->close();

All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: How to use "$ssh->before()"
by ww (Archbishop) on Apr 15, 2015 at 11:59 UTC

    or, alternately (because using icmp may require addtl info)...

    #! /usr/bin/perl -w use 5.018; # cf [id://1123481] -> my $p = Net::Ping->new("icmp"); # method not allowed by (some) hosts, YMMV! my @host_array = ('n+.n+.n+.n+', 'n+.n+.n+.n+', .... ); say "\n Pinging so-and-so(s)\n"; use Net::Ping; my $p = Net::Ping->new("syn"); for my $host (@host_array) { if ($p->ping($host) ) { say "Host $host is alive \n (at least, 'arguably' See doc re +'syn' protocol)\n"; } else { say "Could not ping host $host, $!"; } $p->close(); }