Skip to content

Instantly share code, notes, and snippets.

@keyganker
Last active September 18, 2023 16:26
Show Gist options
  • Save keyganker/993ef859cb4337e6ae6e3736cf1c0478 to your computer and use it in GitHub Desktop.
Save keyganker/993ef859cb4337e6ae6e3736cf1c0478 to your computer and use it in GitHub Desktop.
检查访问指定域名dns解析情况 #shell
#!/bin/bash
# 定义颜色
red(){
echo -e "\033[31m$*\033[0m"
}
green(){
echo -e "\033[32m$*\033[0m"
}
# 定义变量
define_variable(){
# 用户IP信息
export_ip=$(curl -s www.cip.cc|awk -F "[: ]+" '/IP/{print $2}')
export_ip_city=$(curl -s www.cip.cc|awk -F "[:]+" '/地址/{print $2}')
export_ip_ISP=$(curl -s www.cip.cc|awk -F "[:]+" '/运营商/{print $2}')
# 用户所用的DNS信息
DNS_ip=$(awk '/nameserver/{print $2}' /etc/resolv.conf )
# 用户所用的域名信息
domain_resolve_ip=$(dig +short $1|sed -n '$p')
domain_ip_city=$(curl -s www.cip.cc/${domain_resolve_ip}|awk -F "[:]+" '/地址/{print $2}')
domain_ip_ISP=$(curl -s www.cip.cc/${domain_resolve_ip}|awk -F "[:]+" '/运营商/{print $2}')
# 当前时间
time=$(date "+%F %T")
}
# 查看命令帮助信息
help_info(){
green "
Usage:bash $0 [hostname]
"
}
# 输出信息
output_info(){
green "访问的域名:"
echo -e "$1\n"
green "服务器出访IP:"
echo -e "$export_ip\n"
green "服务器出访IP所在城市:"
echo -e "$export_ip_city\n"
green "服务器出访IP所属的ISP:"
echo -e "ISP:$export_ip_ISP\n"
green "DNS服务器IP:"
echo -e "$DNS_ip\n"
green "域名解析的IP:"
echo -e "$domain_resolve_ip\n"
green "域名解析的IP所在的城市:"
echo -e "城市:$domain_ip_city\n"
green "域名解析的IP所属的ISP:"
echo -e "ISP:$domain_ip_ISP\n"
green "当前时间:"
echo $time
}
main(){
define_variable $1
output_info $1
}
if [ ! $1 ]; then
help_info
else
main $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment