-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrtt-root_servers.sh
More file actions
executable file
·84 lines (76 loc) · 2.02 KB
/
rtt-root_servers.sh
File metadata and controls
executable file
·84 lines (76 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
#
# Desc: Check response time and hostname.bind server for each of the root-servers in IPv4 and IPv6
# Author: Mauricio Vergara Ereche <mave@cero32.cl>
# License: GPL-3.0-or-later
#
export PATH=/usr/local/opt/coreutils/libexec/gnubin/:/usr/local/bin:/bin:/usr/bin:/usr/sbin
QRY="CH TXT hostname.bind"
FLAGS="+stats +retry=0 +timeout=1"
IPV="4 6"
function ColorRange(){
if [[ $1 =~ ^-?[0-9]+$ ]] ; then
case $1 in
[1-9]) # Range 1-9 : GREEN
colorcode="\033[1;32m"
;;
[0-2][0-9]) # Range 00-29 : CYAN
colorcode="\033[0;36m"
;;
[3-6][0-9]) # Range 30-69 : BLUE
colorcode="\033[1;34m"
;;
[7-9][0-9]) # Range 80-99 : YELLOW
colorcode="\033[0;33m"
;;
1[0-4][0-9]) # Range 100-149 : BROWN
colorcode="\033[1;33m"
;;
[1-9][5-9][0-9]) # Range 150-999 : RED
colorcode="\033[0;31m"
;;
*)
colorcode="\033[1;35m " # The REST PURPLE
esac
printf "%b%3d%b" ${colorcode} $1 "\033[0m"
else
colorcode="\033[1;35m " # The REST PURPLE
printf "%b%s%b" ${colorcode} ${*} "\033[0m\n"
fi
}
function Query(){
MIN=9999
MAX=0
SUM=0
CONT=1
ipv="-${1}"
for roots in {A..M}; do
ROOT="${roots}.ROOT-SERVERS.NET."
ANSt="$(dig ${FLAGS} ${ipv} @${ROOT} ${QRY} 2>/dev/null |egrep "(Query time|^hostname.bind)" 2>/dev/null)"
if [ $? -eq 0 ] ; then
ANS=$(echo ${ANSt} | awk '{printf "%s",$(NF-1)}')
NAME=$(echo ${ANSt} | cut -d '"' -f2)
printf " ${ROOT}: $(ColorRange ${ANS}) (${NAME})\n"
CONT=$((CONT+1))
else
printf " %s: %bERROR %b\n" ${ROOT} "\033[0;35m" "\033[0m"
fi
if [ $ANS -le $MIN ] ; then MIN=$ANS ; fi
if [ $ANS -ge $MAX ] ; then MAX=$ANS ; fi
SUM=$((SUM+ANS))
done
printf "MIN: $(ColorRange ${MIN}) \n"
printf "AVG: $(ColorRange $((SUM/CONT)) )\n"
printf "MAX: $(ColorRange ${MAX} )\n"
}
ColorRange "Default_routers:"
netstat -rn|grep default|grep -v "fe80::"|awk '{ print $2}'
echo
ColorRange "Default_DNS_Resolver:"
dig . | grep \;\;\ SERVER\: | cut -d ":" -f2-
echo
for ipv in ${IPV}; do
ColorRange "IPv${ipv}:"
Query ${ipv}
echo
done