如下示例代码实现了用telnet命令测试端口连通性的功能:

端口通信正常
-bash-4.1$ echo " " | telnet 192.0.0.1 10100
Trying 10.71.133.9...
Connected to 10.71.133.9.
Escape character is '^]'.
Connection closed by foreign host.

#端口通信异常
-bash-4.1$ echo " " | telnet 192.0.0.1 10100
Trying 192.0.0.1...
telnet: connect to address 192.0.0.1: Connection timed out

Related Posts: telnet 测试端口连通性 :

avatar