Class: Haas::Utils

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

Class Method Summary collapse

Class Method Details

.is_port_open?(ip, port) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/haas/utils.rb', line 4

def self.is_port_open?(ip, port)
  require 'socket'
  require 'timeout'
  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
  end
  return false
end