当前位置:网站首页>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
结果示例

欢迎转载,转载请注明出处,谢谢~
边栏推荐
猜你喜欢
![[Must read] Mylander valuation analysis, electrical stimulation products for pelvic and postpartum rehabilitation](/img/25/e16bac4e789cddadffd43ed9e9df7c.jpg)
[Must read] Mylander valuation analysis, electrical stimulation products for pelvic and postpartum rehabilitation

Application scenarios of js anti-shake function and function throttling

LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之一:解题思路

HikariCP database connection pool, too fast!

Use compilation to realize special effects of love

周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...

Redis数据结构

干货|如何在海量文件系统中选择合适自己的文件系统

后管实现面包屑功能

迭代器失效问题
随机推荐
李航《统计学习方法》笔记之监督学习Supervised learning
It's time for bank data people who are driven crazy by reporting requirements to give up using Excel for reporting
每日一题练习1-15
The 17th day of the special assault version of the sword offer
Navicat连接MySQL时弹出:1045:Access denied for user ‘root’@’localhost’
小程序云开发(十):渐变与动画
用正向迭代器封装实现反向迭代器
图形化矩阵,矩阵到底长什么样?
全新荣威RX5,27寸大屏吸引人,安全、舒适一个不落
迭代器失效问题
DVWA 通关记录 2 - 命令注入 Command Injection
Linux系统卸载,安装,升级,迁移clickHouse数据库
The perceptron perceptron of Li Hang's "Statistical Learning Methods" notes
软件测试与质量 之白盒测试
Spend 2 hours a day to make up for Tencent T8, play 688 pages of SSM framework and Redis, and successfully land on Meituan
php组件漏洞
Rust 从入门到精通03-helloworld
iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
用汇编实现爱心特效【七夕来袭】