← 返回命令列表

Linux command

netcat 命令

网络

需要网络或远程资源。

常用示例

Connect to a host

nc [host] [port]

Listen for incoming connections

nc -l [port]

Listen and keep listening

nc -lk [port]

Scan ports

nc -zv [host] [20-30]

Send a file

nc [host] [port] < [file.txt]

Receive a file

nc -l [port] > [received_file.txt]

Connect via UDP

nc -u [host] [port]

Set a connection timeout

nc -w [5] [host] [port]

Use IPv6

nc -6 [host] [port]

说明

nc (netcat) is a versatile networking utility for reading and writing data across TCP and UDP connections. Often called the "network Swiss army knife," it can create almost any kind of network connection and is invaluable for debugging and testing. Common uses include: port scanning, transferring files, creating simple chat servers, network debugging, and testing network services. In listen mode (-l), nc waits for incoming connections; otherwise it initiates connections to remote hosts. Data is read from stdin and written to stdout, making it easy to pipe data through network connections. Multiple implementations exist (OpenBSD, GNU, ncat from Nmap), with varying feature sets. The -e option for command execution exists in some versions but is omitted from security-focused implementations.

参数

-l
Listen mode; wait for incoming connections
-k
Keep listening after connection closes (with -l)
-n
No DNS lookup; use numeric addresses only
-p _PORT_
Specify source port
-s _ADDR_
Specify source IP address
-u
Use UDP instead of TCP
-v
Verbose output
-w _SECS_
Timeout for connections and idle time
-z
Zero-I/O mode; scan without sending data
-4
Force IPv4 only
-6
Force IPv6 only
-d
Do not read from stdin
-i _SECS_
Delay between lines sent/received
-r
Randomize port numbers
-t
Enable telnet negotiation
-C
Send CRLF line endings
-x _PROXY:PORT_
Connect via proxy
-X _PROTO_
Proxy protocol (4=SOCKS4, 5=SOCKS5, connect=HTTPS)
-U
Use Unix domain sockets
-e _CMD_
Execute command on connection (traditional nc only)

FAQ

What is the netcat command used for?

nc (netcat) is a versatile networking utility for reading and writing data across TCP and UDP connections. Often called the "network Swiss army knife," it can create almost any kind of network connection and is invaluable for debugging and testing. Common uses include: port scanning, transferring files, creating simple chat servers, network debugging, and testing network services. In listen mode (-l), nc waits for incoming connections; otherwise it initiates connections to remote hosts. Data is read from stdin and written to stdout, making it easy to pipe data through network connections. Multiple implementations exist (OpenBSD, GNU, ncat from Nmap), with varying feature sets. The -e option for command execution exists in some versions but is omitted from security-focused implementations.

How do I run a basic netcat example?

Run `nc [host] [port]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -l do in netcat?

Listen mode; wait for incoming connections