Last active
February 23, 2017 12:10
-
-
Save hvmonteiro/353cf50a1ef76a662405994b4e3a8f1c to your computer and use it in GitHub Desktop.
Linux: Test TCP Port when there is no telnet available
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy/paste directly into bash shell or source a file with the function below: | |
# --- cut here --- | |
is_tcp_port_active () { | |
if [ "$1" == "" -o "$2" == "" ]; then | |
echo -e "\n usage: is_tcp_port_active <hostname> <port>\n" | |
return 1 | |
fi | |
HOST=$1; | |
PORT=$2; | |
echo "$HOST:$PORT"; | |
exec 3<>/dev/tcp/${HOST}/${PORT} && echo "Port $PORT opened" || echo "Port $PORT closed"; | |
} | |
# --- end of cut --- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
usage: is_tcp_port_active
Test LDAP (389) port on host 'server01':
Output with success:
Output with error: