Thursday, January 12, 2017

Alternative way to be testing command line if port is open or closed

Trying to find out on a Linux server or under Busybox (Synology) if a TCP port is open or closed? Use this handy command:

exec 6<>/dev/tcp/127.0.0.1/443 || echo "Port is not open"
exec 6>&- # close output connection
exec 6<&- # close input connection

6 is used as the file descriptor. 0,1,2 are stdin, stdout, and stderr. 5 is sometimes used by Bash for child processes, so 3,4,6,7,8, and 9 should be safe.

Alternatively, if the port you're probing is serving the HTTP(S) protocol:

exec 6<>/dev/tcp/127.0.0.1/443
echo -e "GET / HTTP/1.0\n" >&6
cat <&6

Alternative ways are listed here.

No comments:

Post a Comment