fzy-blog

Linux nc 命令

2019-05-24

Linux nc 命令

nc 参数:
-g<网关> 设置路由器跃程通信网关,最多可设置 8 个。
-G<指向器数目> 设置来源路由指向器,其数值为 4 的倍数。
-h 在线帮助。
-i<延迟秒数> 设置时间间隔,以便传送信息及扫描通信端口。
-l 使用监听模式,管控传入的资料。
-n 直接使用 IP 地址,而不通过域名服务器。
-o<输出文件> 指定文件名称,把往来传输的数据以 16 进制字码倾倒成该文件保存。
-p<通信端口> 设置本地主机使用的通信端口。
-r 乱数指定本地与远端主机的通信端口。
-s<来源地址> 设置本地主机送出数据包的 IP 地址。
-u 使用 UDP 传输协议。
-v 显示指令执行过程。
-w<超时秒数> 设置等待连线的时间。
-z 使用 0 输入/输出模式,只在扫描通信端口时使用。

远程拷贝日志文件到本地

从 server1 拷贝文件到 server2 上。需要先在 server2 上,用 nc 激活监听。
server2:
ip: 192.168.200.27

1
nc -l 1234 > 1234.txt

server1:

1
2
3
cat abc.txt
aaaa
nc -w 1 192.168.200.27 1234 < abc.txt
克隆硬盘或分区

操作与上面的拷贝是雷同的,只需要由 dd 获得硬盘或分区的数据,然后传输即可。
克隆硬盘或分区的操作,不应在已经 mount 的的系统上进行。

#server2 上进行类似的监听动作:

1
nc -l -p 1234 | dd of=/dev/sda

#server1 上执行传输,即可完成从 server1 克隆 sda 硬盘到 server2 的任务:

1
dd if=/dev/sda | nc 192.168.200.27 1234
端口扫描
1
2
3
4
5
6
7
8
9
10
11
12
nc -v -w 1 192.168.200.29 -z 20-30
nc: connect to 192.168.200.29 port 20 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 21 (tcp) failed: Connection refused
Connection to 192.168.200.29 22 port [tcp/ssh] succeeded!
nc: connect to 192.168.200.29 port 23 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 24 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 25 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 26 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 27 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 28 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 29 (tcp) failed: Connection refused
nc: connect to 192.168.200.29 port 30 (tcp) failed: Connection refused
聊天(类似 qq 聊天)

server2:

1
2
3
nc -l 1234
hello!
hi!

server1:

1
2
3
nc  192.168.200.27 1234
hello!
hi!
Tags: Linux
使用支付宝打赏
使用微信打赏

若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏

扫描二维码,分享此文章