-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomain-checkNS.sh
More file actions
executable file
·72 lines (57 loc) · 1.78 KB
/
Copy pathdomain-checkNS.sh
File metadata and controls
executable file
·72 lines (57 loc) · 1.78 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
#!/bin/bash
if [[ "${1:-}" == "-a" || "${1:-}" == "--author" ]]; then
echo "Author: FoxSecIntel"
echo "Repository: https://github.com/FoxSecIntel/DNS-analysis
echo "Tool: domain-checkNS.sh"
exit 0
fi
set -euo pipefail
VERSION="1.2.0"
__r17q_blob="wqhWaWN0b3J5IGlzIG5vdCB3aW5uaW5nIGZvciBvdXJzZWx2ZXMsIGJ1dCBmb3Igb3RoZXJzLiAtIFRoZSBNYW5kYWxvcmlhbsKoCg=="
if [[ "${1:-}" == "m" || "${1:-}" == "-m" ]]; then
echo "$__r17q_blob" | base64 --decode
exit 0
fi
if [[ "${1:-}" == "-v" || "${1:-}" == "--version" ]]; then
echo "domain-checkNS.sh $VERSION"
exit 0
fi
usage() {
cat <<'EOF'
Usage:
domain-checkNS.sh -d <domain> [-n "ns1,ns2,ns3"]
Options:
-d DOMAIN Domain to check (required)
-n NS_LIST Comma-separated expected NS list
default: ns1.example.com,ns2.example.com,ns3.example.com
EOF
}
domain=""
expected_csv="ns1.example.com,ns2.example.com,ns3.example.com"
while getopts ":d:n:h" opt; do
case "$opt" in
d) domain="$OPTARG" ;;
n) expected_csv="$OPTARG" ;;
h) usage; exit 0 ;;
\?) echo "Invalid option -$OPTARG"; usage; exit 1 ;;
esac
done
[[ -n "$domain" ]] || { echo "Error: domain required"; usage; exit 1; }
mapfile -t expected < <(echo "$expected_csv" | tr ',' '\n' | sed 's/\.$//' | tr '[:upper:]' '[:lower:]')
mapfile -t found < <(dig +short NS "$domain" | sed 's/\.$//' | tr '[:upper:]' '[:lower:]')
[[ ${#found[@]} -gt 0 ]] || { echo "No name servers found for $domain."; exit 1; }
declare -a missing=()
for ns in "${expected[@]}"; do
if printf '%s\n' "${found[@]}" | grep -qx "$ns"; then
echo -e "\033[32mMatch: $ns\033[0m"
else
echo -e "\033[31mMissing expected NS: $ns\033[0m"
missing+=("$ns")
fi
done
echo
echo "Actual NS for $domain:"
printf '%s\n' "${found[@]}"
if [[ ${#missing[@]} -gt 0 ]]; then
exit 2
fi