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.

SysOps·36 commands·Last updated 2026-07-21
Back to SysOps

Connect & Port Scan 6

nc -zv host 80
检测目标 80 Port是否开放,最常用
nc -zv host 80 443 8080
Check多个指定Port
nc -zv host 1-1000
扫描 1-1000 Port范围
nc -vz -w 2 host 80
带 2 秒timeout检测Port
nc -uz host 8080
UDP 模式检测Port
nc -4 host 80
force使用 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)

Advanced Options 7

-v / -vv
verboseOutput / 更verboseOutput
-z
零 I/O 模式,仅扫描不发送数据
-w 2
Connectiontimeout 2 秒
-k
保持监听,supports多个Connection(BSD 版)
-s 192.168.1.1
指定源 IP 地址
-p 12345
指定本地源Port
-u
使用 UDP 协议

Alternatives 4

ncat host 80
Nmap 的 ncat,supports SSL 和访问控制
ncat --ssl host 443
ncat 加密Connection,替代明文 nc
socat - TCP:host:80
socat 功能更强的替代,supports更多协议
nc --version
Show 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