telnet版

#!/bin/bash

file="/home/sinova/bin/iplist.txt"

tong="/home/sinova/bin/tong.txt"

butong="/home/sinova/bin/butong.txt"

while read ip port;do

    T=$((sleep 1;)|telnet ${ip} ${port}|awk 'NR==3{if($0 ~ "]")print "ok"}')

    if [[ ${T} == "ok" ]];then

        echo "${ip} ${port} is yes" >>${tong}

    else

        echo "${ip} ${port} is no" >>${butong}

    fi

done <${file}

nc版

#!/bin/bash

file="/home/sinova/bin/iplist.txt"

tong="/home/sinova/bin/nctong.txt"

butong="/home/sinova/bin/ncbutong.txt"

while read ip port;do

    T=$((sleep 1;)|nc -w 5 -vz ${ip} ${port}|awk '{if($0 ~ "succeeded!")print "ok"}')

    if [[ ${T} == "ok" ]];then

        echo "${ip} ${port} is yes" >>${tong}

    else

        echo "${ip} ${port} is no" >>${butong}

    fi

done <${file}