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)
Just for completeness, the Bash would be something like this:
$ netcat $HOST $PORT -w 1 -q 0 </dev/null && do_something
-w 1
specifies a timeout of 1 second, and -q 0
says that, when connected, close the connection as soon as stdin
gives EOF
(which /dev/null
will do straight away).
Bash also has its own built-in TCP/UDP services, but they are a compile-time option and I don't have a Bash compiled with them :P