# nc --help
Ncat 7.50 ( https://nmap.org/ncat )
Usage: ncat [options] [hostname] [port]
Options taking a time assume seconds. Append 'ms' for milliseconds,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
-4 Use IPv4 only
-6 Use IPv6 only
-U, --unixsock Use Unix domain sockets only
-C, --crlf Use CRLF for EOL sequence
-c, --sh-exec Executes the given command via /bin/sh
-e, --exec Executes the given command
--lua-exec Executes the given Lua script
-g hop1[,hop2,...] Loose source routing hop points (8 max)
-G Loose source routing hop pointer (4, 8, 12, ...)
-m, --max-conns Maximum simultaneous connections
-h, --help Display this help screen
-d, --delay
nc常用案例
TCP监听测试
nc可作为server端192.168.10.11启动一个tcp的监听
nc -l 80
客户端测试方法:直接telnet该机器ip+端口
telnet 192.168.10.11 80
或:nmap 192.168.10.11 -p 80
UDP监听测试
nc作为server端启动一个udp的监听
nc -lu 80
通过netstat可以看到udp协议已经监听:
> # netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:80 0.0.0.0:* 15401/nc