-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnscheck
executable file
·44 lines (34 loc) · 1.09 KB
/
dnscheck
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
#!/bin/bash
MAXRTT=0
MINRTT=999
SUM=0
die () {
printf "Error, exiting: " 1>&2
echo "$@" 1>&2
exit 255
}
for X in time bc dig; do
which "${X}" >/dev/null 2>&1 || die "required application ${X} not found"
done
[ -z ${1} ] && exit 1
BCFUNK="define max(a,b){if(a>b){return(a)}else{return(b)}} define min(a,b){if(a>b){return(b)}else{return(a)}}"
round() {
echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
};
CT="$(date +%Y%m%d\ %H:%M:%S)"
for ((X=0;X<15;X++)) ; do
RTT[$X]=$(/usr/bin/time -f %e dig @${1} google.com +short 2>&1 >/dev/null)
done
#get sum & other stuff
for ((X=0;X<15;X++)); do
SUM=$(echo "${SUM} + ${RTT[$X]}"| bc -l)
MINRTT=$(echo "${BCFUNK} min(${MINRTT},${RTT[$X]})" |bc -l)
MAXRTT=$(echo "${BCFUNK} max(${MAXRTT},${RTT[$X]})" |bc -l)
done
#AVG=$(echo ${SUM}/15 |bc -l)
#AVG=$(round $AVG 2)
#printf "Sum of real time for 15 queries: $SUM\n"
#printf "Average query time: $AVG\n"
#printf "Min RTT: $MINRTT\n"
#printf "Max RTT: $MAXRTT\n"
printf "$CT $SUM $MINRTT $MAXRTT\n"