备注,使用方法:当前目录下要存在需要测试的地址端口,例子:
cat ip.txt
141.12.65.17 7500
#!/bin/bash
cur_dir=$(pwd)
ipfile=$cur_dir/ip.txt
logfile=$cur_dir/log.txt
date=date
echo "****${date}" >> $logfile
if [ ! -f "$ipfile" ]; then
echo "系统检查到在当前路径下不存在要测试的地址清单,请补充ip.txt要测试的地址清单 EXIT"
exit
fi
if [ ! -f "$logfile" ]; then
touch $cur_dir/log.txt
fi
cat $ipfile | while read line
do
result=echo -e "\n" | telnet $line 2> /dev/null | grep Connected | wc -l
if [ $result -eq 1 ]; then
echo " $line network is nomral" >> $logfile
else
echo " $line network is warried" >> $logfile
fi
done