ubuntu port ping 1

ubuntu port ping

# Use the below command in your terminal
# No requirments are needed
(echo >/dev/tcp/{host}/{port}) &>/dev/null && echo "open" || echo "close"

# An example below
(echo >/dev/tcp/10.20.20.21/27017) &>/dev/null && echo "open" || echo "close"

# if open then it will return "open"
# if closed then it will return "close"
# if you can't connect to it then it will freeze, use ctrl+c

Here is what the above code is Doing:
1. The first part of the command is the echo command.
2. The second part of the command is the >/dev/tcp/{host}/{port}
3. The third part of the command is the &>/dev/null
4. The fourth part of the command is the && echo “open”
5. The fifth part of the command is the || echo “close”

1. The echo command is used to send a message to the terminal.
2. The >/dev/tcp/{host}/{port} is used to connect to the host and port.
3. The &>/dev/null is used to redirect the output to null.
4. The && echo “open” is used to print “open” if the connection is successful.
5. The || echo “close” is used to print “close” if the connection is unsuccessful.

Similar Posts