examples/ssh_to_ec2_instance.rb
# Method will try to connect to given IP and port.
# It will return true if this port is open.
Method will try to connect to given IP and port.
It will return true if this port is open.
Method will try to connect to given IP and port . It will return true if this port is open .
def is_port_open?(ip, port)
  return false if ip==""
  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
def is_port_open? ( ip , port ) return false if ip == "" 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
Method will try to connect to given IP and port.
Method will try to connect to given IP and port .
ip
<not_specific>
port
<not_specific>