netcat (NC) listen for open ports

The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6. Unlike telnet(1), nc scripts nicely, and separates error messages onto standard error instead of sending them to standard output, as telnet(1) does with some.

Example to listen for 443
nc -z 443

This is what a successful result will look like
Connection to port 80 [tcp/http] succeeded!

What follows is a macos bash script that prompts the user for a comma delimited list of hostnames in terminal, if there is more than one and processes the following netcat terminal command(s) to derive open port information for each hostname and subsequent IP address on an array of hardcoded ports.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Share via
Copy link