summaryrefslogtreecommitdiffstats
path: root/scripts/ping.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/ping.pl')
-rwxr-xr-xscripts/ping.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/ping.pl b/scripts/ping.pl
new file mode 100755
index 0000000..0f24483
--- /dev/null
+++ b/scripts/ping.pl
@@ -0,0 +1,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();