-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckDNS.sh
More file actions
47 lines (41 loc) · 1.34 KB
/
checkDNS.sh
File metadata and controls
47 lines (41 loc) · 1.34 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
#!/bin/bash
#To use this script, run ./checkA.sh {hostname} {query type a|ptr|soa}
host=$1
#Get all of the DNS servers in AD into $array[]
mapfile -t array < <(nslookup -type=NS hcbocc.ad | grep hcbocc.ad | cut -f 2 -d "=" | cut -f 2 -d " " | sort)
#Add the Umbrella servers
array+=(
"ctyctr-umbva1.hcbocc.ad"
"ctyctr-umbva2.hcbocc.ad"
"psoc-umbva1.hcbocc.ad"
"psoc-umbva2.hcbocc.ad"
"sp-umbva1.hcbocc.ad"
"sp-umbva2.hcbocc.ad"
)
#Run the test and display the output
for i in ${!array[@]}; do
if [ -z ${2} ]; then
echo "Missing command variable"
echo "Usage ./checkDNS.sh {query} {query type a|ptr|soa}"
exit
elif [ $2 == "a" ]; then
output=$(dig +short $host @${array[$i]})
elif [ $2 == "soa" ]; then
output=$(dig -t soa +short $host @${array[$i]})
elif [ $2 == "ptr" ]; then
output=$(dig -x $host @${array[$i]} | grep PTR | grep -v ";")
else
echo "Unknown command variable $2"
echo "Usage ./checkDNS.sh {query} {query type a|ptr|soa}"
exit
fi
if [ $(echo $output | wc -c) -le 2 ]; then
output="No result"
fi
len=$(echo ${array[$i]} | wc -c)
if [ $len -le 18 ]; then
echo -e ${array[$i]} says:'\t \t \t' $output
elif [ $len -ge 18 ]; then
echo -e ${array[$i]} says:'\t \t' $output
fi
done