- #!/bin/sh
- file=/etc/list
- eno=0;
- rno=0;
- sum=0;
- if [ "$2" == "" ];then
- num=100
- else
- num=$2
- fi
- while read line
- do
- if [ "$num" -eq "$sum" ];then
- break
- fi
- # sum=$(expr $sum + 1)
- ip[$sum]=`echo $line | sed -n 's/^.*(\(.[0-9\.]*\)).*$/\1/p'`
- addr[$sum]=`echo $line | sed -n 's/^\(.*\)(.*/\1/p'`
- result[$sum]=`nslookup $1 ${ip[$sum]} | grep Address | sed -n '2,$p' | cut -d: -f2`
- sum=$(expr $sum + 1)
- #echo ${ip[$sum]}
- #echo ${result[$sum]}
- echo -n "."
- done < $file
- echo
- for line in `seq 1 $sum`
- do
- t=$(expr $line - 1)
- if [ "${result[$line]}" = "" ];then
- # result=" Error!!"
- echo -n " "$line"=>"
- echo -en "\033[32m ${addr[$t]} \033[0m:"
- echo -e "\033[37m "Error"($1) \033[0m"
- eno=$( expr $eno + 1 )
- else
- echo -n " "$line"=>"
- echo -en "\033[32m ${addr[$t]} \033[0m:"
- echo -e "\033[31m ${result[$t]}($1) \033[0m"
- rno=$( expr $rno + 1 )
- fi
- done
- echo "========================================"
- echo -n "eno="$eno";rno="$rno";"
- echo -n "Error=" `echo $eno $sum | awk '{print $1 / $2 * 100 "%;";}'`
- echo "Success=" `echo $rno $sum | awk '{print $1 / $2 * 100 "%;";}'`
- echo "========================================"
- #file文件内容格式如下:
- 广西南宁市铁通(222.52.118.162)
广西南宁市铁通(222.52.118.163)
河南省电信(222.85.85.85)
河南省洛阳市电信(222.88.88.88)
云南省电信(222.172.200.68)
湖南省电信(222.243.129.81)
其中红色这句执行很非常的慢,循环起来非常耗时,想有什么好的方法来解决这个问题,但又不影响功能,如果你看到了,还请指教。
阅读(3927) | 评论(2) | 转发(0) |