With this script you can check if a remote machine is listening on port 22, which is the default SSH port.
port=22
timeout=5

if (( "$#" != 1 )); then
   echo "usage: $(basename $0) HOST"
fi

host=$1

if nc -w $timeout -z $host $port; then
   echo "Yes"
else
   echo "No"
fi

Updated: