Simple test if TCP port is open

Caveat Lector: This blog post was published 8 years ago. Depending on the content, it may no longer be applicable or relevant.

There are other more complicated tools to achieve the same (like nmap whose manpage makes your head spin), but this is a very simple solution using netcat:

nc -zv 127.0.0.1 80

To programmatically evaluate the result, use the standard Bash $? variable. It will be set to 0 if the port was open, or 1 if the port was closed.

If you found a mistake in this blog post, or would like to suggest an improvement to this blog post, please get in touch at michael@franzl.name; as subject please use the prefix "Comment to blog post" and append the post title.
 
Copyright © 2023 Michael Franzl