Version:20180419
#!/bin/bash ###############DNS拨测脚本 V1 20180419 ###############By PlatoWG ##备份原resolv.conf文件 /bin/cp /etc/resolv.conf /etc/resolv.conf.back ##脚本主体 success=0 fail=0 read -p "请输入拨测次数:" num echo "nameserver 114.114.114.114" > /etc/resolv.conf for i in `seq 1 $num` do NO=`curl -I http://www.caict.ac.cn/|grep -w HTTP|grep -w HTTP|awk '{print $2}'` &> /dev/null clear;echo "第${i}次拨测,HTTP返回状态$NO" if [ $NO -eq 200 ];then let success+=1 ;else let fail+=1 fi sleep 0.1 done clear;echo "拨测完成,拨测结果如下:" echo 共拨测成功${num}次 echo 拨测成功${success}次 echo 拨测失败${fail}次 rm -rf /etc/resolv.conf mv /etc/resolv.conf.back /etc/resolv.conf
Version:20180421 增加回显拨测起止时间;增加自定义拨测DNSIP,拨测域名,拨测次数;增加回显拨测信息确认
#!/bin/bash ###############DNS拨测脚本 V1 20180419 ###############By PlatoWG ##备份原resolv.conf文件 /bin/cp /etc/resolv.conf /etc/resolv.conf.back ##脚本主体 success=0 fail=0 read -p "请输入DNSIP:" dns read -p "请输入拨测次数:" num read -p "请输入拨测域名:" domain echo "nameserver $dns" > /etc/resolv.conf echo -e "请确认拨测信息:DNSIP:$dns \n拨测次数:$num \n拨测域名:$domain" read -p "请输入y/n确认信息" confirm if [ $confirm != "y" ];then exit 0 fi begin_time=`date "+%F %T"` for i in `seq 1 $num` do NO=`curl -I $domain|grep -w HTTP|grep -w HTTP|awk '{print $2}'` &> /dev/null clear;echo "第${i}次拨测,HTTP返回状态$NO" if [ $NO -eq 200 ];then let success+=1 ;else let fail+=1 fi sleep 0.1 done end_time=`date "+%F %T"` clear;echo "拨测完成,拨测结果如下:" echo "拨测时间:$begin_time--$end_time" echo 共拨测成功${num}次 echo 拨测成功${success}次 echo 拨测失败${fail}次 rm -rf /etc/resolv.conf mv /etc/resolv.conf.back /etc/resolv.conf