W
W0rtex Indigo
require 'socket'
require 'timeout'
def ping( host, service = "echo",timeout = 2)
begin
timeout( timeout ){
TCPSocket.open( host, service){}
}
rescue Errno::ECONNREFUSED
true
rescue false
else true
end
end
p ping(ARGV[0] || "google.ru")
When host is down i got error:" ping:10:in `ping': class or module
required for rescue clause (TypeError) from ping:14"
when host is alive i've got true
Can you help me please!
require 'timeout'
def ping( host, service = "echo",timeout = 2)
begin
timeout( timeout ){
TCPSocket.open( host, service){}
}
rescue Errno::ECONNREFUSED
true
rescue false
else true
end
end
p ping(ARGV[0] || "google.ru")
When host is down i got error:" ping:10:in `ping': class or module
required for rescue clause (TypeError) from ping:14"
when host is alive i've got true
Can you help me please!