cat /root/iplist.txt | while read line
do
result=`echo -e "\n" | telnet $i 2>/dev/null | grep Connected | wc -l`
if [ $result -eq "1" ]; then
echo "$i Network is Open."
else
echo "$i Network is Closed."
fi
done
此处必须使用while read line,不能使用for循环,因为传参时会带上单引号,从sh -vx xxx.sh可以看到过程
/root/iplist.txt格式为每行一条IP空格端口,例如
192.168.2.1 1201
192.168.2.2 1202
192.168.2.3 1203
192.168.2.4 1204
192.168.2.5 1205