linux: 用nc测试端口是否打开

一,说明

nc命令全称是netcat。其主要功能如下:
1.测试udp端口的连通性(重点)。 nc -z -v -u 172.16.100.101 8826
2.测试tcp端口的连通性。 nc -z -v 172.16.100.101 22

参数 :

 -u      Use UDP instead of the default option of TCP.

-v      Have nc give more verbose output.

-z      Specifies that nc should just scan for listening daemons, without sending any data to them.  It is an error to use this option in conjunction with the -l option.

u表示udp端口,
v表示可视化输出,
z表示扫描时不发送数据

如果机器上没有安装telnet,用nc也是一个很好的工具选择

二,实际应用例子

连接成功

% nc -z -v 8.9.10.13 8890
Connection to 8.9.10.13 port 8890 [tcp/ddi-tcp-3] succeeded!

连接失败,被拒绝

% nc -z -v 8.9.10.13 8899
nc: connectx to 8.9.10.13 port 8899 (tcp) failed: Connection refused

 

posted @ 2025-07-05 08:45  刘宏缔的架构森林  阅读(132)  评论(0)    收藏  举报