Reputation: 767
I need to do check whether the remote machine is pinging so that i can do ssh to that machine and execute commands over there. how to do this check in perl?
Upvotes: 0
Views: 824
Reputation: 1160
A simple and fast test that a host is listening on a particular port can be done using IO::Socket::INET
use IO::Socket::INET;
my $address_tuple = "$ip:$port";
my $test_sock = IO::Socket::INET->new(PeerAddr => $address_tuple, Timeout => 0.15);
if ( $test_sock) {
# Host is up and appears to be listening on that port
$test_sock->close();
}
else {
# Host doesn't appear to be listening on that port
}
Upvotes: 1