module IsPortOpen

Public Instance Methods

port_open?(ip, port = 22) click to toggle source
# File lib/rodeo_clown/is_port_open.rb, line 6
def port_open?(ip, port = 22)
  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

  false
end