-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWalkDNSCache-loop-proto.ps1
61 lines (54 loc) · 1.88 KB
/
WalkDNSCache-loop-proto.ps1
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
#global
#Continue options (comment/uncomment)
#$DebugPreference = "Continue"
#$InformationPreference = "Continue"
#$warningpreference = "Continue"
#Silent continue options (comment/uncomment)
$DebugPreference = "SilentlyContinue"
$InformationPreference = "SilentlyContinue"
$warningpreference = "SilentlyContinue"
$results = Get-DnsClientCache
$intFwdLookupCount = 0
$intRevLookupCount = 0
$results
Write-Debug "===Parsing==="
$intDepthControl = 7
foreach($result in $results){
if($result.Entry -like "*.in-addr.arpa")
{
$intRevLookupCount = $intRevLookupCount +1
$strOut = "Rev:" + $result.Entry
Write-Information $strOut
}
else
{
$thisDepth = 0
$intFwdLookupCount = $intFwdLookupCount + 1
Write-Debug "entering ELSE"
$thisCacheEntry = $result.Entry
Write-debug "Fwd:$thisCacheEntry"
$subs= $thisCacheEntry.Split(".")
Write-debug $subs.Count
$thisDepth = 0
if($subs.Count -gt 1)
{
Write-debug ">>>New:$thisCacheEntry<<<"
while($thisDepth -le ($subs.Count-2) -and ($thisDepth -lt $intDepthControl))
{
$intSubCount = $subs.Count
$strCount = 'Substring count:{0}' -f $intSubCount
Write-debug $strCount
Write-debug "This depth:$thisDepth"
$thisNodeLabel = $subs[($subs.Count-2-$thisDepth)]
$thisArrSubs = $subs[($subs.Count-2 - $thisDepth)..($subs.Count-1)]
$thisNodeID = [string]::Join(".",$thisArrSubs)
$thisDepth = $thisDepth + 1
Write-Host "ID:$thisNodeID"
Write-Host "Label:$thisNodeLabel"
}
Write-debug ">>>End<<<"
}
}
}
Write-Host "Forward lookups: $intFwdLookupCount"
Write-Host "Reverse lookups: $intRevLookupCount"