【Linux命令】nc

NetCat,在网络工具中有“瑞士军刀”美誉,其有Windows和Linux的版本。因为它短小精悍,功能实用,被设计为一个简单、可靠的网络工具, 可通过TCP或UDP协议传输读写数据。同时,它还是一个网络应用Debug分析器,因为它可以根据需要创建各种不同类型的网络连接。

[[email protected] ~]$ nc -h
[v1.10]
connect to somewhere:	nc [-options] hostname port[s] [ports] ...
listen for inbound:	nc -l -p port [-options] [hostname] [port]
options:
	-g gateway	source-routing hop point[s], up to 8
	-G num		source-routing pointer: 4, 8, 12, ...
	-h		this cruft
	-i secs		delay interval for lines sent, ports scanned
	-l		listen mode, for inbound connects
	-n		numeric-only IP addresses, no DNS
	-o file		hex dump of traffic
	-p port		local port number
	-r		randomize local and remote ports
	-s addr		local source address
	-u		UDP mode
	-v		verbose [use twice to be more verbose]
	-w secs		timeout for connects and final net reads
	-z		zero-I/O mode [used for scanning]
port numbers can be individual or ranges: lo-hi [inclusive]



1.监听本地端口

nc -l -p 1234             #开启监听
netstat -tunlp | grep 1234 #查看
2.端口扫描

nc -v -w 10 10.1.1.180 80
nc -v -w 10 10.1.1.180 -z 80-30000
3.文件传输

源10.1.1.43 text.txt ;目的 10.1.1.180

nc -l -p 1234 > test.txt                
#开10.1.1.180:1234端口监听,并将socket传输过来的数据重定向到test.txt文件 
nc  10.1.1.180 1234 < test.txt
#连接远程的10.1.1.180,从test.txt的路径定向到socket,从而将文件传输到远方。



4.目录传输

源10.1.1.43 python_program;目的 10.1.1.180

nc -l -p 1234 | tar xzvf -
tar czvf -  python_program | nc 10.1.1.180 1234



5.测试UDP端口

[email protected]:web#netstat -tunlp
[email protected]:~# nc -vuz  172.16.211.34 68



你可能感兴趣的:(【Linux命令】nc)