linux中nc详解


|是管道符号,表示左边的输出作为右边的输入。

 

1、TCP端口扫描

# nc -v -z -w2 127.0.0.1 1-100
Connection to 127.0.0.1 22 port [tcp/ssh] succeeded!
Connection to 127.0.0.1 53 port [tcp/domain] succeeded!
Connection to 127.0.0.1 80 port [tcp/http] succeeded!
...
nc: connect to 127.0.0.1 port 100 (tcp) failed: Connection refused

2、从192.168.1.2拷贝文件到192.168.1.3

首先在接收端192.168.1.3上: nc -l 1234 > test.txt

然后在发送端192.168.1.2上: nc 192.168.1.3 < test.txt

注意:先运行接收端,指定一个端口为1234,文件为test.txt,再执行发送端,并且发送端必须存在同名的文件test.txt

3、传输目录

从server1(192.168.16.233)拷贝nginx目录内容到server2(192.168.48.47)上。需要先在server2上,用nc激活监听,

server2上运行:# nc -l 1234 | tar xzv-

server1上运行:# tar czv- nginx | nc 192.168.48.47 1234 

4、简单聊天工具

在192.168.1.2上: nc -l 1234

在192.168.1.3上: nc 192.168.1.2 1234

这样,双方就可以相互交流了。使用ctrl+C(或D)退出


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM