Permalink
Browse files

Ruby 1.9 does not support ping natively anymore, add the module here

  • Loading branch information...
1 parent a4f6d73 commit 2b0ae34cc90f5ecc3111191d014aa406b9843853 @nialscorva nialscorva committed Feb 16, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/ping.rb
View
@@ -0,0 +1,18 @@
+require 'timeout'
+require 'socket'
+
+class Ping
+ def self.pingecho(host, timeout=5, service="echo")
+ begin
+ timeout(timeout) do
+ s = TCPSocket.new(host, service)
+ s.close
+ end
+ rescue Errno::ECONNREFUSED
+ return true
+ rescue Timeout::Error, StandardError
+ return false
+ end
+ return true
+ end
+end

0 comments on commit 2b0ae34

Please sign in to comment.