-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns_record_audit.sh
More file actions
executable file
·59 lines (50 loc) · 1.54 KB
/
dns_record_audit.sh
File metadata and controls
executable file
·59 lines (50 loc) · 1.54 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
#!/usr/bin/env bash
set -euo pipefail
# dns_record_audit.sh
# Audits DNS records (A, AAAA, MX, NS, TXT, CNAME) for domains from a file.
usage() {
cat <<'EOF'
Usage: ./dns_record_audit.sh --input domains.txt [options]
Options:
--input FILE Domain list file (required)
--server NS Query specific DNS server (optional)
--types LIST Comma-separated types (default: A,AAAA,MX,NS,TXT,CNAME)
--timeout SECONDS dig timeout (default: 3)
-h, --help Show help
EOF
}
INPUT_FILE=""
SERVER=""
TYPES="A,AAAA,MX,NS,TXT,CNAME"
TIMEOUT=3
while [[ $# -gt 0 ]]; do
case "$1" in
--input) INPUT_FILE="$2"; shift 2 ;;
--server) SERVER="$2"; shift 2 ;;
--types) TYPES="$2"; shift 2 ;;
--timeout) TIMEOUT="$2"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown option: $1"; usage; exit 1 ;;
esac
done
if [[ -z "$INPUT_FILE" || ! -f "$INPUT_FILE" ]]; then
echo "Missing input file: $INPUT_FILE"
exit 1
fi
IFS=',' read -r -a type_array <<< "$TYPES"
while IFS= read -r domain; do
[[ -z "$domain" || "$domain" =~ ^# ]] && continue
echo "=== $domain ==="
for record_type in "${type_array[@]}"; do
if [[ -n "$SERVER" ]]; then
result="$(dig +time="$TIMEOUT" +tries=1 +short "$domain" "$record_type" @"$SERVER" | paste -sd ';' -)"
else
result="$(dig +time="$TIMEOUT" +tries=1 +short "$domain" "$record_type" | paste -sd ';' -)"
fi
if [[ -z "$result" ]]; then
result="NO_RECORD"
fi
printf "%-6s %s\n" "$record_type" "$result"
done
echo
done < "$INPUT_FILE"