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

欢迎转载,转载请注明出处,谢谢~
边栏推荐
- Use the scrapy to climb to save data to mysql to prevent repetition
- 练习16-两道模拟题
- 让电商运营10倍提效的自动化工具,你get了吗?
- One Summer of Open Source | How to Quickly Integrate Log Modules in GO Language Framework
- 单词接龙 II
- Nodejs3day(express简介,express创建基本Web服务器,托管静态资源,nodemon下载及出现的问题,中间件,编写GET,POST,JSONP接口)
- node封装一个图片拼接插件
- 【New Edition】DeepFakes: Creation, Detection and Influence
- 阿里巴巴 CTO 程立:开源是基础软件的源头!
- Shell脚本实现多选DNS同时批量解析域名IP地址(新更新)
猜你喜欢

Redis数据结构

李航《统计学习方法》笔记之朴素贝叶斯法

牛客网项目2.7开发注册功能 报错This application has no explicit mapping for /error......

The perceptron perceptron of Li Hang's "Statistical Learning Methods" notes

【OpenCV】-霍夫变换

日元疲软令游戏机在日本变身“理财产品”:黄牛大赚

日元疲软令游戏机在日本变身“理财产品”:黄牛大赚

Do you agree with this view?Most businesses are digitizing just to ease anxiety
![[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

Facebook自动化数据分析方案,广告投放省心省力
随机推荐
Getting Started with SCM from Scratch (1): Summary of Background Knowledge
iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
理解JS的三座大山
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
AutoJs学习-实现科赫雪花
R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
Re23:读论文 How Does NLP Benefit Legal System: A Summary of Legal Artificial Intelligence
mysql进阶(二十一)删除表数据与数据库四大特性
leetcode 62. Unique Paths(独特的路径)
Chapter 15 Generics
周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...
Long battery life or safer?Seal and dark blue SL03 comparison shopping guide
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化水平柱状图(条形图)、使用orientation参数设置柱状图转置为条形图
function call to print lua internal structure
AutoJs学习-实现谢尔宾斯基三角
从零开始入门单片机(一):必会背景知识总结
DVWA 通关记录 2 - 命令注入 Command Injection
Use compilation to realize special effects of love
ConvNeXt论文及实现