Linux学习之路

linux nc命令

2019-06-29  本文已影响3人  FilesFan

概述

nc命令是一个功能强大的网络工具,通过它不仅可以探测端口,还能作为客户端连接服务。

语法及参数

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

2.参数

示例

1.端口扫描。这样可以快速扫描对应ip的端口是否监听。

root@ce85f80a5f15:~# nc -vz -w 2 www.baidu.com -z 80-85
Connection to www.baidu.com 80 port [tcp/http] succeeded!
nc: connect to www.baidu.com port 81 (tcp) timed out: Operation now in progress
nc: connect to www.baidu.com port 82 (tcp) timed out: Operation now in progress
nc: connect to www.baidu.com port 83 (tcp) timed out: Operation now in progress
nc: connect to www.baidu.com port 84 (tcp) timed out: Operation now in progress
nc: connect to www.baidu.com port 85 (tcp) timed out: Operation now in progress

2.简单的聊天工具。这个就是一个使用C/S模式,模拟的聊天工具。我这边client端是172.19.0.3,server端是172.19.0.2。

server:监听端口
nc -l 6666
client: 连接server的对应端口
nc 172.19.0.2 6666
使用ctrl+C(或D)退出。

3.拷贝文件。这个原理比较简单,和上面的聊天工具一个道理,只是把信息直接输入到文件中了。

在172.19.0.2上: nc -l 1234 > test.txt
在172.19.0.3上: nc 192.168.2.34 < test.txt

4.建立从本地6666端口到www.baidu.com的80端口连接,5秒超时
nc -p 6666 -w 5 www.baidu.com 80

上一篇 下一篇

猜你喜欢

热点阅读