To test a connection use nc

# nc -vz myhost 22 -w 15 > /dev/null 2>&1

-w 15 is the timeout

Will return 0 if the host connects on ssh port 22
or 1 if it does not connect.

Updated: 03/29/2016

The new update to the nc command takes this option away.

Instead the following will work

timeout 60s /bin/bash -c 2>/dev/null >/dev/tcp/myhost/22

Test port connection
*from the man pages

On one console, start nc listening on a specific port for a connection.

# nc -l 1234

nc is now listening on port 1234 for a connection. On a second console (or a second machine), connect to the machine and port being listened on:

# nc 127.0.0.1 1234

There should now be a connection between the ports. Anything typed at the second console will be concatenated to the first, and vice-versa. The connection may be terminated using an EOF.