Check if a certain port is opened on Linux

In this example below, I need to check if the port 22 (SSH) is opened.


#!/bin/sh

if nc -w 3 localhost 22 <<< ” &> /dev/null
then
echo ‘Port is open’
else
echo ‘Port is closed’
fi

Leave a Reply