How to test open ports w/o telnet or nc

Found this out of necessity when a security team didn’t allow the installation of either telnet or nc. I initially thought ssh would work, but it doesn’t really work.

The command is simple. Just do this:

/dev/tcp/<host>/<port>

Replace the <host> and <port>. Here’s how it would look if successful:

SV-LT-1361:~ altonyu$ > /dev/tcp/192.168.0.11/2049
SV-LT-1361:~ altonyu$ echo $?
0

Here’s how it would look if unsuccessful:

SV-LT-1361:~ altonyu$ > /dev/tcp/192.168.0.11/2047
-bash: connect: Connection refused
-bash: /dev/tcp/192.168.0.11/2047: Connection refused
SV-LT-1361:~ altonyu$ echo $?
1

Obviously if the command hangs, it probably means it won’t work either.

Hope this helps someone!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.