Skip to main content

nc (netcat) command

Detailed Explanation

nc (or netcat) is often referred to as the "Swiss Army knife" of networking. It is a utility used for reading from and writing to network connections using TCP or UDP. It can be used for port scanning, transferring files, creating simple chat servers, and even setting up reverse shells.

Basic Syntax

nc [options] [hostname] [port[s]]

Common Flags/Options

OptionDescription
-lListen mode, for inbound connects.
-p <port>Local port number.
-uUse UDP instead of the default option of TCP.
-vVerbose output.
-zZero-I/O mode (used for scanning).
-nDo not do any DNS or service lookups.

Real-world Examples

Scan a single port to see if it's open:

nc -zv 192.168.1.1 80

Scan a range of ports:

nc -zv 192.168.1.1 20-30

Start a simple listening server on port 1234:

nc -l -p 1234

Connect to the listening server:

nc 192.168.1.100 1234

Transfer a file (Receiver):

nc -l -p 1234 > received_file.txt

Transfer a file (Sender):

nc 192.168.1.100 1234 < file_to_send.txt