天天看点

linux shell 批量telnet测试端口

#! /bin/bash



# timout_second:超时时间,秒
# host: 域名
# port: 端口
# echo -e '\x1dclose\x0d' | timeout --signal=9 {timout_second} telnet {host} {port}
# timeout 指定命令运行时长
#         -s  --signal=9 超时发出信号

while read ip
do
    if [[ "$ip" == "" ]]; then  continue; fi

    echo -ne "\r $ip:43300 ...."
    ret=`echo -e '\x1dclose\x0d' | timeout --signal=9 1 telnet $ip 43300`;
    connected=`echo $ret | grep "Connected"`;
    if [[ $connected != "" ]]; then
        echo " .... Ok"
    fi
done < $1