Top 10 Netcat Commands for Advanced Networking
Top 10 Netcat Commands for Advanced Networking
A practical reference for advanced Netcat (nc) usage: commands, parameters, examples, and when to use them for troubleshooting, testing, and automation.
Why Netcat
Netcat is a lightweight, scriptable networking utility for TCP/UDP I/O. It can open raw connections, listen for traffic, transfer files, and pipe data to programs. Implementations vary (traditional netcat, OpenBSD netcat, Ncat), so check nc --help or your man page for local flags.
Top 10 Commands
Simple TCP Connect
Open a TCP connection to a host and port for connectivity checks and banner grabbing.
nc example.com 80
Listen Mode (Server)
Start a TCP listener to accept incoming connections—useful for quick servers, file receives, or reverse shells.
nc -l -p 4444
UDP Mode
Use UDP instead of TCP to test UDP services and protocols.
nc -u -l -p 53
Zero I/O Mode (Port Scanning)
Scan a range of ports by checking which ports accept connections without sending data.
nc -z -v example.com 20-1024
Bind to Specific Local Interface
Choose the source IP/interface for outgoing connections—useful on multi‑homed hosts or when testing routing.
nc -s 192.168.1.10 example.com 80
Execute Program on Connect
Run a local program (e.g., a shell) when a connection is established. Many builds omit this flag for safety.
nc -l -p 4444 -e /bin/bash
Keep Listening After Disconnect
Allow the listener to accept multiple sequential connections without restarting.
nc -k -l -p 8080
Timeouts and Connection Control
Set connection and I/O timeouts to avoid hanging operations in scripts or tests.
nc -w 5 example.com 22
nc -q 2 -l -p 1234
Transfer Files Between Hosts
Send or receive files over a raw TCP connection using shell redirection—simple and scriptable for trusted networks.
# Sender
nc -l -p 9000 < file.tar.gz
# Receiver
nc host.example.com 9000 > file.tar.gz
IPv4 / IPv6 Selection and Numeric Addresses
Force IPv4/IPv6 or skip DNS lookups to avoid dual‑stack ambiguity or DNS issues.
nc -4 192.0.2.10 80
nc -6 [2001:db8::1] 80
nc -n example.com 80
Quick Reference
-e).
Comments
Post a Comment