Using netcat (nc) to check for open ports
By Steve Claridge on 2021-11-01.
Netcat (often abbreviated to nc) is a command-line network tool for reading/writing TCP and UDP connections.
In scan-only mode, netcat will check to see if a specific port is open on a given host and return yes/no. In other modes, netcat will read or write data to a host using TCP or UDP, but here we are just checking to see if the port is open, no data is sent.
This is a useful way to check firewall rules to make sure your machine is secure. It is also useful if you need to check if your application is listening on a specific port.
-z option is the scan-only flag, so here we are checking to see if the HTTP port is open
nc -z -v 18.104.22.168 80
-v is for verbose output, without this flag nc will not tell you if the port is closed.
We can also scan a range of ports in one go
nc -z -v 22.214.171.124 1-1000
Depending on which OS you are using, the command may be called
netcat or it may be
nc. MacOS uses
nc, Ubuntu allows both and Windows uses