DEV Community

pgrz
pgrz

Posted on

Checking port visibility without net tools

Note: these are my self-help notes. Please let me know if they're wrong :)

The only thing you have is pure bash - no net tools. How to check the port visibility on a remote machine?

1. Opening stream for the TCP connection

exec [stream number]<>/dev/tcp/[host]/[port]

e.g.:
exec 5<>/dev/tcp/10.21.24.41/22

2. Sending something to that port

echo "hello" >&5

3. Reading the answer

cat <&5

In case the port 22 is open, we'll get something like:

SSH-2.0-OpenSSH_7.4
Protocol mismatch.
Enter fullscreen mode Exit fullscreen mode

4. Closing the stream descriptor

exec 5<&-

Top comments (0)