Class: Rays::Utils::NetworkUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/rays/utils/network_utils.rb

Class Method Summary collapse

Class Method Details

.port_open?(ip, port) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rays/utils/network_utils.rb', line 29

def port_open?(ip, port)
  begin
    Timeout::timeout(1) do
      begin
        s = TCPSocket.new(ip, port)
        s.close
        return true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
        return false
      end
    end
  rescue Timeout::Error
    return false
  end

  false
end