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 10.0.1.1 443

This is what a successful result will look like
Connection to 10.0.1.1 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.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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