-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns
More file actions
116 lines (105 loc) · 3.66 KB
/
dns
File metadata and controls
116 lines (105 loc) · 3.66 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
# Simple DNS probe script using dig
# Usage: ./check-dns.sh TARGET DOMAIN [OUTPUT_FILE]
# Example: ./check-dns.sh 10.10.10.10 example.com
set -euo pipefail
IFS=$'\n\t'
TARGET="${1:-10.10.10.10}"
DOMAIN="${2:-example.com}"
OUTPUT_FILE="${3:-$(date -u +'%Y%m%dT%H%M%SZ')_${TARGET//./_}_dns.log}"
# helper: timestamped log prefix
log() {
printf '%s %s\n' "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" "$*"
}
# check that dig is available
if ! command -v dig >/dev/null 2>&1; then
echo "ERROR: dig not found in PATH. Install bind9-dnsutils / BIND tools or use WSL/Git-Bash/Cygwin."
exit 2
fi
# run a dig query and annotate output
run_dig() {
local desc="$1"; shift
log ">>> $desc" >>"$OUTPUT_FILE"
# Use +noall +answer for concise answers; remove if you want full output
dig +noall +answer "$@" >>"$OUTPUT_FILE" 2>&1 || {
log "dig command failed for: $desc" >>"$OUTPUT_FILE"
}
log ">>> end $desc" >>"$OUTPUT_FILE"
printf '\n' >>"$OUTPUT_FILE"
}
# Start fresh log (append if you'd prefer to keep previous results, change >> to >>)
: >"$OUTPUT_FILE"
# Queries
run_dig "NS records for $DOMAIN using server $TARGET" ns "$DOMAIN" @"$TARGET"
run_dig "CHAOS TXT version.bind on $TARGET" CH TXT version.bind @"$TARGET"
run_dig "ANY records for $DOMAIN using server $TARGET" any "$DOMAIN" @"$TARGET"
run_dig "AXFR (zone transfer) for $DOMAIN from $TARGET" axfr "$DOMAIN" @"$TARGET"
# maybe use +tcp
echo "Wrote results to $OUTPUT_FILE"
# POWERSHELL
# <#
# Usage:
# .\Check-Dns.ps1 -Target 10.10.10.10 -Domain example.com -OutputFile .\dns.log
#
# Notes:
# - Uses Resolve-DnsName where possible, falls back to nslookup for AXFR.
# - CH class (CHAOS) queries (e.g., version.bind) are not universally supported by Resolve-DnsName/nslookup on all Windows builds.
# - If you need exact parity with dig, install dig (BIND utils) or use WSL.
# #>
#
# param(
# [string]$Target = "10.10.10.10",
# [string]$Domain = "",
# [string]$OutputFile = ("{0:yyyyMMddTHHmmssZ}_{1}_dns.log" -f (Get-Date).ToUniversalTime(), ($Target -replace '\.','_'))
# )
#
# function Log {
# param($msg)
# $ts = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
# "$ts $msg" | Out-File -FilePath $OutputFile -Append -Encoding utf8
# }
#
# # Ensure file exists / clear
# '' | Out-File -FilePath $OutputFile -Encoding utf8
#
# # NS records
# try {
# Log ">>> Resolve-DnsName -Type NS -Server $Target $Domain"
# Resolve-DnsName -Name $Domain -Type NS -Server $Target | Out-String | ForEach-Object { Log $_ }
# Log ">>> end NS"
# } catch {
# Log "Resolve-DnsName NS failed: $_"
# }
#
# # version.bind (CHAOS class) - may not work with Resolve-DnsName
# try {
# Log ">>> Try to query version.bind (CHAOS) - may be unsupported"
# # Resolve-DnsName doesn't support class selection; attempt TXT query for version.bind
# Resolve-DnsName -Name "version.bind" -Type TXT -Server $Target | Out-String | ForEach-Object { Log $_ }
# Log ">>> end version.bind"
# } catch {
# Log "version.bind query failed: $_"
# }
#
# # ANY records
# try {
# Log ">>> Resolve-DnsName -Type ANY -Server $Target $Domain"
# Resolve-DnsName -Name $Domain -Type ANY -Server $Target | Out-String | ForEach-Object { Log $_ }
# Log ">>> end ANY"
# } catch {
# Log "Resolve-DnsName ANY failed: $_"
# }
#
# # AXFR (zone transfer) - use nslookup if available (AXFR requires server permission)
# try {
# Log ">>> Attempt AXFR using nslookup (if server allows zone transfer)"
# $nsCmd = "nslookup -type=axfr $Domain $Target"
# Log "CMD: $nsCmd"
# $out = cmd.exe /c $nsCmd 2>&1
# $out | ForEach-Object { Log $_ }
# Log ">>> end AXFR"
# } catch {
# Log "AXFR attempt failed: $_"
# }
#
# Write-Host "Wrote results to $OutputFile"