#! /usr/local/bin/ruby

## Perl module sample (ICMP ping)
## 1998 by yoshidam
##
## This script must be setuid root.

require 'perl'

if ARGV.length == 0
  print "#{$0} <hostname> [<timeout>]\n"
  exit 1
end
hostname = ARGV[0]
timeout = 5
if ARGV.length > 1
  timeout = ARGV[1].to_i
end

perl = Perl.new("/dev/null")
p = perl.eval("use Net::Ping; new Net::Ping('icmp')")
if p.ping(hostname, timeout) == 1
  print hostname + " is alive\n"
else
  print "no answer from " + hostname + "\n"
end
p.close
