netcat Cheatsheet - Network Debugging
All essential netcat commands organized by use case, with 36+ entries you can copy and run directly. Find the right command fast when you need it.
Back to SysOpsConnect & Port Scan 6
nc -zv host 80检测目标 80 Port是否开放,最常用
nc -zv host 80 443 8080Check多个指定Port
nc -zv host 1-1000扫描 1-1000 Port范围
nc -vz -w 2 host 80带 2 秒timeout检测Port
nc -uz host 8080UDP 模式检测Port
nc -4 host 80force使用 IPv4 Connection
File & Data Transfer 6
nc -l 9999 > received.txt接收端:监听并Save到File
nc host 9999 < file.txt发送端:发送File
tar czf - dir | nc host 9999发送端:打packageconcurrency送Directory
nc -l 9999 | tar xzf -接收端:接收并Extract
dd if=/dev/sda | nc host 9999发送端:传输Disk镜像
nc host 9999 | pv > disk.img接收端:带进度条接收镜像(需 pv)
Port Listen 5
nc -l 8080监听本地 8080 PortawaitConnection
nc -l -p 8080监听(老版本 nc 语法,需 -p)
nc -l -k 8080保持监听,supports多个Connection(BSD 版)
nc -lk 8080同上,merge写法
nc -lu 9090监听 UDP Port
Proxy & Forward 3
nc -l 1234 | nc target 80简易 TCP 代理转发
mkfifo pipe; nc -lk 8080 < pipe | nc target 80 > pipe双向Port转发(pipe方式)
nc -l 1234 -e /bin/bash将 shell 绑定到Port(GNU nc,仅限授权Test)
Banner 5
echo "" | nc host 22抓取 SSH Service版本号
echo "" | nc host 25抓取 SMTP Service Banner
printf "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | nc example.com 80发送原始 HTTP request
echo -e "GET / HTTP/1.0\r\n\r\n" | nc example.com 80Show HTTP response头
nc host 3306抓取 MySQL Service Banner
Advanced Options 7
-v / -vvverboseOutput / 更verboseOutput
-z零 I/O 模式,仅扫描不发送数据
-w 2Connectiontimeout 2 秒
-k保持监听,supports多个Connection(BSD 版)
-s 192.168.1.1指定源 IP 地址
-p 12345指定本地源Port
-u使用 UDP 协议
Alternatives 4
ncat host 80Nmap 的 ncat,supports SSL 和访问控制
ncat --ssl host 443ncat 加密Connection,替代明文 nc
socat - TCP:host:80socat 功能更强的替代,supports更多协议
nc --versionShow nc 版本,区分 BSD/GNU/OpenBSD 版
💡 Tips
- macOS 自带的 nc 是 BSD 版本,Options和 GNU ncat 不同,排障时note区分。
- Port扫描仅用于授权范围内的Network排查,未经授权扫描属违规行为。
- nc 传输不加密,敏感数据不要直接用 nc 传,走 SSH 或 TLS。
- OpenBSD 版 nc 不supports -e Options,需要绑定 shell 时用 ncat 或 socat 替代。
- 传输大File时发送端用 pv Display进度:pv file.txt | nc host 9999。
- 做Port转发prefer socat 或 ncat,功能更完善且supports持久Connection。
Official References
Commands are compiled from the official docs below. Click to verify the latest usage.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Found an error? Report it
Wrong command or description? Open an issue to help us fix it.
Found an error? Report it