检测端口是否开启

sh-4.1# nc -w 5 baidu.com 80 && echo ok
ok
sh-4.1# nc -w 5 baidu.com 81
sh-4.1# echo $?
1
sh-4.1# nc -w 5 baidu.com 80
sh-4.1# echo $? #返回上面命
0

telnet 查看端口是否开启:

sh-4.1# telnet baidu.com 84
Trying 111.13.101.208...
telnet: connect to address 111.13.101.208: Connection timed out

百度开了80,而并没开84所以,连84端口失败

sh-4.1# telnet baidu.com 80
Trying 123.125.114.144...
Connected to baidu.com.
Escape character is '^]'.
原文地址:https://www.cnblogs.com/bass6/p/6085082.html