检测脚本:
#!/bin/bash
for ip in `cat ip.txt |awk '{print $1}'`
do
port=`cat ip.txt |grep -w $ip|awk '{print $2}'`
num=`sleep 1 | timeout -t 1 telnet $ip $port |grep "]"|wc -l`
if [ $num -eq 1 ]
then
echo "$ip:$port" >> result_open.txt
else
echo "$ip:$port" >> result_closed.txt
fi
done
ip.txt模板:
192.168.3.160 22
172.16.10.141 9334