I need a quick way to find out if a given port is open with Ruby. I currently am fiddling around with this:
require \'socket\'
def is_port_open?(ip, port)
All other existing answer are undesirable. Using Timeout
is discouraged. Perhaps things depend on ruby version. At least since 2.0 one can simply use:
Socket.tcp("www.ruby-lang.org", 10567, connect_timeout: 5) {}
For older ruby the best method I could find is using non-blocking mode and then select
. Described here: