Linux – check if a remote port is open

 

By using nc(Netcat) command we can check if a port in remote machine is opened or closed.

Here is an example to check if remote port is opened or closed:

STATUS=$(nc -z you_remote_host 80 ; echo $?)

if [ $STATUS -eq 0 ]
then
    echo "Port is opened"
else
    echo "Port is opened"
fi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s