use Net::Ping; $hostname = 'elvis'; # host to check $timeout = 10; # how long to wait for a response print "elvis is alive\n" if pingecho($hostname, $timeout);
The parameters for
The remote host to check, specified either as a hostname or as an IP address.
The timeout in seconds. If not specified it will default to 5 seconds.
pingecho()uses alarm to implement the timeout, so don't set another alarm while you are using it.