nc:强大的网络工具

2017-09-29  本文已影响33人  dshowing

nc,全称netcat,被称为网络工具中的“瑞士军刀”,通过TCP和UDP在网络中读写数据。通常用于网络的检查、调试以及针对服务和端口的扫描。
除此之外,发现nc还有一个NB的功能:数据传输。可以摒弃scp、ftp使用nc进行传文件的操作

netcat.jpg

主要用法

nc [-hlnruz] [-g <网关>] [-G <指向器数目>] [-i <延迟秒数>] [-o <输出文件>] [-p <通信端口>] [-s <源地址>] [-v ] [-w <超时秒数>] [主机名] [目的端口]

主要选项:

使用实例

TCP扫描

~# nc -v -z -w 5 192.168.1.106 80
nc: connect to 192.168.159.168 port 80 (tcp) failed: Connection refused
~# nc -v -z -w 5 192.168.1.106 22
Connection to 192.168.159.168 22 port [tcp/ssh] succeeded!

UDP扫描

~# nc -v -z -u 192.168.1.112 47808
Connection to 103.42.212.207 47808 port [udp/*] succeeded!

文件传输

目的主机监听指定端口,重定向到要接受的文件名
nc -l 4444 > file.tar.bz2

源主机发起请求,进行传输
nc www.dst_host.com 4444 < file.tar.bz2

官方引用

DATA TRANSFER
The example in the previous section can be expanded to build a basic data transfer model. Any information input into one end of the connection will be output to the other end, and input and output can be easily captured in order to emulate file transfer.
Start by using nc to listen on a specific port, with output captured into a file:
$ nc -l 1234 > filename.out
Using a second machine, connect to the listening nc process, feeding it the file which is to be transferred:
$ nc host.example.com 1234 < filename.in
After the file has been transferred, the connection will close automatically.

上一篇 下一篇

猜你喜欢

热点阅读