Linux Command - nc

nc - Netcat utility

Syntax

1
nc [options] host port

Description

Netcat is one of the most powerful networking tools, security tools, and network monitoring tools.

It can be used for

  • Network debugging tool
  • Port scan
  • Port listening

Options

Option Description
-l Listen mode, used to create a server that listens for incoming connections.
-n disable DNS lookup to avoid delays
-n, –no-clobber do not override existing file
-v, –verbose verbose mode, provides more details
-z Scans for open ports.

Example

Check if port is open

check if github.com port 443 is open

1
nc -vz github.com 443

output

1
Connection to github.com port 443 [tcp/https] succeeded!

You can also use IP address instead of hostname

1
nc -vz 140.82.112.3 443

Port Scanning

Port scanning is a common technique to discover open ports. It can be considered hostile. Please only use it on your own hosts.

Scan port 1 to 100

1
nc -vz localhost 1-100 2>&1 | grep succeeded

Listen to incoming connection

1
nc -l 4000

Reference