in reply to Net::SSH::Perl hanging on creating object

Dealing with network timeouts is tricky, your code can hang while resolving the hostname, the host can be slow, blocking your SYNs, your ACKs if it's really evil etc. I usually take the lazy approach and backtick nmap, relying on its excellent detection techniques:
perl -e '$a=`nmap -sS -P0 -p 22 --host-timeout 30s -oG - hostname.doma +in`; if($a=~/Status: (\w+).*?Ports: 22\/(\w+)/gsi) {print "Host statu +s: $1, SSH service: $2\n"} else {warn $a}'

Replies are listed 'Best First'.
Re^2: Net::SSH::Perl hanging on creating object
by i5513 (Pilgrim) on Jun 09, 2011 at 17:25 UTC
    I think nc approach is better:
    if ( ! system ("nc -z -w 2 myexample.com 22 2> /dev/null")) { print "ok"."\n" }
    Regards,