NetCat,在網絡工具中有「瑞士軍刀」美譽,其有Windows和Linux的版本。由於它短小精悍,功能實用,被設計爲一個簡單、可靠的網絡工具, 可經過TCP或UDP協議傳輸讀寫數據。同時,它仍是一個網絡應用Debug分析器,由於它能夠根據須要建立各類不一樣類型的網絡鏈接。 python
[yuechangchang@cp01-rdqa-dev376.cp01.baidu.com ~]$ 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.監聽本地端口 web
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-300003.文件傳輸
源10.1.1.43 text.txt ;目的 10.1.1.180 shell
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 dom
nc -l -p 1234 | tar xzvf - tar czvf - python_program | nc 10.1.1.180 1234
5.測試UDP端口 socket
root@172.16.211.34:web#netstat -tunlp root@172.16.211.35:~# nc -vuz 172.16.211.34 68