#!/usr/bin/perl -w use Net::Ping; use Switch; if (@ARGV >1) { $host=$ARGV[0]; $timeout=$ARGV[1]; } elsif (@ARGV>0) { $host=$ARGV[0]; $timeout=2; } else { print "Usage is: $0 host \n"; exit; } if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; } else { $port = 22; } $p=Net::Ping->new('tcp'); $p->port_number($port); if ($p->ping($host, $timeout)) {print 1;} else {print 0;} $p->close();