Bash has native redirection that can check for open ports
host=192.168.1.99
if (echo > "/dev/tcp/${host}/22") >/dev/null 2>&1; then
echo 'port is open'
else
echo 'port is closed'
fi
or you can use nc(1):
host=192.168.1.99
if timeout 3 nc -z "$host" 22 2>/dev/null; then
echo 'port is open'
else
echo 'port is closed'
fi
You can also use telnet programmatically by piping it to something like grep:
host=192.168.1.99
if telnet "$host" 22 2>&1 | grep -q "Connected""Connected"; then
echo 'port is open'
else
echo 'port is closed'
fi