5
shell脚本实现批量解析域名IP地址(支持多DNS)
source link: https://blog.51cto.com/u_15538119/5471412
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
shell脚本实现批量解析域名IP地址(支持多DNS)
原创#!/bin/bash
#Author:cosann
#Create Time:20220714
#Description:批量解析域名A记录和CNAME记录脚本
#初始化DNS服务器
dns1=$1
dns2=$2
dns3=$3
#初始化解析库
dns_file=$4
#DNS检测函数定义
function Ping_Stat_1 (){
ping -w 1 $dns1 &> /dev/null
if [ "`echo $?`" == 0 ]
then
return 100
else
return 200
fi
}
function Ping_Stat_2 (){
ping -w 1 $dns2 &> /dev/null
if [ "`echo $?`" == 0 ]
then
return 100
else
return 200
fi
}
function Ping_Stat_3 (){
ping -w 1 $dns3 &> /dev/null
if [ "`echo $?`" == 0 ]
then
return 100
else
return 200
fi
}
echo -e "DNS连通性检测中,请稍等"
#DNS检测函数调用
Ping_Stat_1
code1=`echo $?`
Ping_Stat_2
code2=`echo $?`
Ping_Stat_3
code3=`echo $?`
#DNS解析控制及解析功能实现
if [ "$code1" == 100 ];then
echo -e "DNS:$dns1 OK\n"
echo -e "DNS1(IP:$dns1)"
echo -e "域名\t\t\tA记录/CNAME 记录"
cat $dns_file | while read line
do
dig @$dns1 $line A +short | sed "s/^/$line\t\t/g"
done
echo -e "\n"
else
echo -e "DNS:$dns1 NG" && echo -e "目标DNS网络不可达!"
fi
if [ "$code2" == 100 ];then
echo -e "DNS:$dns2 OK\n"
echo -e "DNS2(IP:$dns2)"
echo -e "域名\t\t\tA记录/CNAME记录"
cat $dns_file | while read line
do
dig @$dns2 $line A +short | sed "s/^/$line\t\t/g"
done
echo -e "\n"
else
echo -e "DNS:$dns2 NG" && echo -e "目标DNS网络不可达!"
fi
if [ "$code3" == 100 ];then
echo -e "DNS:$dns3 OK\n"
echo -e "DNS3(IP:$dns3)"
echo -e "域名\t\t\tA记录/CNAME记录"
cat $dns_file | while read line
do
dig @$dns3 $line A +short | sed "s/^/$line\t\t/g"
done
else
echo -e "DNS:$dns3 NG" && echo -e "目标DNS网络不可达!"
fi
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK