手里有一批域名要核对,大约1200个;而且做了智能DNS,有三个运营商,分别为:电信、联通、移动。脚本中的dns ip为本地运营商
域名文件名:filename.运营商e文缩写
域名文件格式应为:“域名 解析地址 MX权重”,按要求只处理(A|CNAME|MX)这几个,其余省略。
# Module: 最后的最后,验证三个文件信息内容:[ dnsinfo.telecom dnsinfo.cnc dnsinfo.cmb(or cmcc) ]
# 描述:1.验证数据和运营商数据是否一致
# 要求:固定文件目录为:/home/zhangwei/dnsinfo/文件名
# 输入文件名:[ dnsinfo.telecom dnsinfo.cnc dnsinfo.cmb ]
recheck_dnsinfo(){
echo "--- 开始验证: ${1} ---"
dos2unix ${1}
carrier=`echo ${1} | awk -F'.' '{print $2}'`
case "${carrier}" in
telecom)
dnsserver="202.100.192.68"
;;
cnc)
dnsserver="221.11.132.2"
;;
cmb)
dnsserver="211.138.164.6"
;;
*)
echo "Error when get internet carrier:${carrier}"
esac
final_dir="/home/zhangwei/tydns/dnsinfo"
cd ${final_dir}
while read line
do
domainname=`echo ${line}|awk -F' ' '{print $1}'`
dnstarget=`echo ${line}|awk -F' ' '{print $2}'`
mx_weight=`echo ${line}|awk -F' ' '{print $3}'`
if [ "${mx_weight}" = "" ];then
search_result=`dig @${dnsserver} ${domainname} +short`
search_count=`echo ${search_result} | grep ${dnstarget} | wc -l`
case "${search_count}" in
0)
#结果不一致,错误
search_status="Fail"
;;
1)
#结果一致,正确
search_status="Ok"
;;
*)
#多个匹配结果,不明确
search_status="Unknow"
esac
else
search_result=`dig @${dnsserver} mx ${domainname} +short`
search_mxtarget=`echo ${search_result}| awk -F' ' '{print $2}'`
search_mxweight=`echo ${search_result}| awk -F' ' '{print $1}'`
if [ "${search_mxtarget}" == "${dnstarget}" ] && [ "${search_mxweight}" == "${mx_weight}" ];then
search_status="Ok"
else
search_status="Fail"
fi
fi
case "${search_status}" in
Ok)
echo -e "${domainname}\t${dnstarget}\tok\t${mx_weight}" >> ${final_dir}/recheck.dnsinfo.${carrier}
;;
*)
echo -e "${domainname}\t${dnstarget}\t${search_result}\t${mx_weight}" >> ${final_dir}/recheck.dnsinfo.${carrier}
esac
done < ${1}
}
# 开始运行
filename="dnsinfo.telecom dnsinfo.cnc dnsinfo.cmb"
for i in ${filename[@]}
do
recheck_dnsinfo ${i}
done