当前位置:网站首页>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
结果示例
欢迎转载,转载请注明出处,谢谢~
边栏推荐
- 日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
- 一款优秀的中文识别库——ocr
- R语言时间序列数据的平滑:使用KernSmooth包的dpill函数和locpoly函数对时间序列数据进行平滑以消除噪声
- php组件漏洞
- 链表的实现
- Tencent T8 architect, teach you to learn small and medium R&D team architecture practice PDF, senior architect shortcut
- AutoJs学习-实现谢尔宾斯基三角
- 用了TCP协议,就一定不会丢包嘛?
- R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化堆叠的柱状图(stacked bar plot)、lab.pos参数指定柱状图的数值标签的位置,lab.col参数指定数值标
- The 17th day of the special assault version of the sword offer
猜你喜欢
Spend 2 hours a day to make up for Tencent T8, play 688 pages of SSM framework and Redis, and successfully land on Meituan
Naive Bayesian Method of Li Hang's "Statistical Learning Methods" Notes
Using the TCP protocol, will there be no packet loss?
【Redis】通用命令
Verilog的随机数系统任务----$random
链表的实现
从零开始入门单片机(一):必会背景知识总结
Nodejs3day(express简介,express创建基本Web服务器,托管静态资源,nodemon下载及出现的问题,中间件,编写GET,POST,JSONP接口)
Two-dimensional array piecemeal knowledge sorting
matlab-day02
随机推荐
关于缓存数据的探讨
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化堆叠的柱状图(stacked bar plot)、lab.pos参数指定柱状图的数值标签的位置,lab.col参数指定数值标
李航《统计学习方法》笔记之朴素贝叶斯法
Pytorch的LSTM参数解释
SAP 云平台上一种 Low Code Development(低代码开发)解决方案
One Summer of Open Source | How to Quickly Integrate Log Modules in GO Language Framework
使用scrapy 把爬到的数据保存到mysql 防止重复
HikariCP数据库连接池,太快了!
HikariCP database connection pool, too fast!
AutoJs学习-实现谢尔宾斯基三角
AutoJs学习-实现科赫雪花
软件测试X模型
打印lua内部结构的函数调用
Rust 从入门到精通03-helloworld
重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化、使用diff函数计算对数化后的时间序列数据的逐次差分(计算价格的对数差分)
Using the TCP protocol, will there be no packet loss?
带你认识40G单纤双向光模块-QSFP+ BiDi光模块
1对1视频源码——快速实现短视频功能提升竞争力
Do you agree with this view?Most businesses are digitizing just to ease anxiety