summaryrefslogtreecommitdiffstats
path: root/scripts/ping.pl
blob: 0f24483f619d430c3caff34939d1162173f05044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/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 <timeout=1>\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();