Netcat Section 1 of 14

Basic Usage

Netcat (nc) is a simple yet powerful networking utility that reads and writes data across network connections using TCP or UDP protocols. It's often called the "Swiss Army knife" of networking tools due to its versatility.

Basic Syntax

The basic syntax for Netcat is:

nc [options] host port

host: Target hostname or IP address

port: Target port number

[options: Various flags to modify behavior

Connection Modes

Netcat operates in two primary modes:

Client Mode (Default)

Connects to a remote host and port. This is the default behavior when you specify a host and port.

nc example.com 80

Listen Mode (-l)

Listens for incoming connections on a specified port. Use the -l flag to enable listen mode.

nc -l 4444

Simple Examples

Connect to a Web Server

Establish a TCP connection to a web server on port 80:

nc example.com 80

After connecting, you can manually type HTTP requests:

GET / HTTP/1.1Host: example.com<Enter><Enter>

Listen for Connections

Listen for incoming TCP connections on port 4444:

nc -l 4444

UDP Connection

Use UDP instead of TCP with the -u flag:

nc -u example.com 53