当前位置:网站首页>Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
2022-08-02 09:57:00 【isk--cosann】
background text
The script was in the original《shellThe script implements batch resolution of domain namesIP地址(支持多DNS)》On the basis of the code logic optimization and small details code update,Important changes are listed below:
Add any multiple choiceDNS逻辑,That is, the target may not be selected during executionDNS,只需指定DNS_File文件(默认DNS为114.114.114.114,There are custom requirements can be modified by themselves)
实现代码
#!/bin/bash
#Author:cosann
#Function:批量解析域名A记录和CNAME记录脚本
#version:2.0
#Create Time:20220714
#Update Time: 20220801
#Description:
#1.支持DNSIPArgument judgment
#2.支持DNSParse the domain name file to determine
#3.自定义多选DNS(默认DNS:114.114.114.114,Up to three are supportedDNS解析)
clear #Clear the screen while the script is running
#Prompt for script information
cat <<EOF ============================================= == Welcome to the DNS resolution script ===== --------------------------------------------- #1.Author:Cosann #2.Function:批量解析域名A记录和CNAME记录脚本 #3.version:2.0 #4.Description: - 支持DNSIPArgument judgment - 支持DNSParse the domain name file to determine - 自定义多选DNS(默认DNS:114.114.114.114 Up to three are supportedDNS解析) ============================================= EOF
echo #换行
#初始化默认DNS服务器
dns=114.114.114.114
#定义DNSText detection function
function dns_file_cleck () {
if ! [ -f "$dns_file" ]
then
echo "$4文件错误,Please check the text file"
exit
fi
}
#定义DNSNetwork detection function
function Ping_Stat_1 (){
ping -w 1 $dns1 &> /dev/null #ping测试
if [ "`echo $?`" == 0 ]
then
return 100 #返回DNSThe target network reachability value
else
return 200 #返回DNSTarget network unreachable value
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
}
#Parameter transmission detection and execution control
if [ $# -eq "1" ]
then
dns1=$dns;dns_file=$1;
echo -e "DNS:$dns1\tDNS_File:$PWD/$dns_file\n"
dns_file_cleck #调用DNSText detection function
Ping_Stat_1 #DNS检测函数调用
code1=`echo $?`
elif [ $# -eq "2" ]
then
dns1=$1;dns_file=$2
echo -e "DNS:$dns1\tDNS_File:$PWD/$dns_file\n"
dns_file_cleck
Ping_Stat_1
code1=`echo $?`
echo $code1
elif [ $# -eq "3" ]
then
dns1=$1;dns2=$2;dns_file=$3
echo -e "DNS:$dns1 $dns2\tDNS_File:$PWD/$dns_file\n"
dns_file_cleck
Ping_Stat_1
code1=`echo $?`
Ping_Stat_2
code2=`echo $?`
elif [ $# -eq "4" ]
then
dns1=$1;dns2=$2;dns3=$3;dns_file=$4
echo -e "DNS:$dns1 $dns2 $dns3\tDNS_File:$PWD/$dns_file\n"
dns_file_cleck
Ping_Stat_1
code1=`echo $?`
Ping_Stat_2
code2=`echo $?`
Ping_Stat_3
code3=`echo $?`
else
echo -e "Usage: $0 dns1 dns2 dns3 dns_file"
exit
fi
echo -e "》》》DNS连通性检测中,请稍等》》》"
#DNS解析控制及解析功能实现
if [ "$code1" == 100 ];then
echo -e "-------------------------------------------\n"
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"
elif [ "$code1" == 200 ];then
echo -e "DNS:$dns1 NG" && echo -e "目标DNS网络不可达!\n"
fi
if [ "$code2" == 100 ];then
echo -e "-------------------------------------------\n"
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"
elif [ "$code2" == 200 ];then
echo -e "DNS:$dns2 NG" && echo -e "目标DNS网络不可达!\n"
fi
if [ "$code3" == 100 ];then
echo -e "-------------------------------------------\n"
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
elif [ "$code3" == 200 ];then
echo -e "DNS:$dns3 NG" && echo -e "目标DNS网络不可达!\n"
fi
exit 0
使用方法
Prepare script files and DNS_File文件
DNS_File文件内容格式

1. 只指定DNS_File文件运行脚本(Use script default settings114.114.114.114进行解析)
./dns.sh host
2. 指定一个DNS服务器运行脚本
./dns.sh 8.8.8.8 host
3. 指定两个DNS服务器运行脚本
./dns.sh 8.8.8.8 114.114.114.114 host
4. 指定三个DNS服务器运行脚本
./dns.sh 8.8.8.8 114.114.114.114 192.168.222.1 host
结果示例

欢迎转载,转载请注明出处,谢谢~
边栏推荐
- 链表的实现
- Pytorch的LSTM参数解释
- The ggline function of the R language ggpubr package visualizes grouped line graphs, the add parameter is mean_se and dotplot to visualize line graphs of different level averages, and adds error bars
- R语言使用zoo包中的rollapply函数以滚动的方式、窗口移动的方式将指定函数应用于时间序列、设置align参数指定结果数据中的时间标签取自窗口中的位置(参数right指定取自窗口的最右侧)
- typeinfo类型支持库学习
- MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
- MySql千万级分页优化,快速插入千万数据方法
- Overview of Edge Computing Open Source Projects
- Re22:读论文 HetSANN An Attention-based Graph Neural Network for Heterogeneous Structural Learning
- 软件测试H模型
猜你喜欢
随机推荐
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
Chapter 15 Generics
Facebook's automated data analysis solution saves worry and effort in advertising
Application scenarios of js anti-shake function and function throttling
中国发布丨滴滴因违反网络安全法等被罚80.26亿元!调查细节公布
Shell脚本实现多选DNS同时批量解析域名IP地址(新更新)
【OpenCV】-霍夫变换
php组件漏洞
【Redis】通用命令
从零开始入门单片机(一):必会背景知识总结
未知内容监控
Long battery life or safer?Seal and dark blue SL03 comparison shopping guide
第十五章 多线程
Facebook自动化数据分析方案,广告投放省心省力
剑指offer专项突击版第17天
The k-nearest neighbor method in the notes of Li Hang's "Statistical Learning Methods"
Do you agree with this view?Most businesses are digitizing just to ease anxiety
The realization of the list
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚









