我正在尝试编写shell脚本来testing服务器是否能够达到指定的IP和端口。
我正在使用的命令: ncat -w 5 <IP> 636 or 389 > /dev/null 2>&1 < /dev/null | echo $? ncat -w 5 <IP> 636 or 389 > /dev/null 2>&1 < /dev/null | echo $? 问题是当我检查上述两个端口的退出码我收到1。
当我运行它没有/ dev / null我得到一个连接到IP。
ncat -v -w 5 <IP> 636 Ncat: Version 6.40 ( http://nmap.org/ncat ) Ncat: Connected to <IP>:636. ^C
问题是如果我使用第二个命令没有/ dev / null,我需要手动取消命令使用: CTRL + C
任何build议,我怎么可以testingip和ldap端口使用ncat或nc?
尝试使用-z标志。 如果有的话。
-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.
所以试试这个
ncat -z -w 5 <IP> 636