Created
July 12, 2017 09:14
-
-
Save fsackur/409d7b36895c2887c68068d2785c2c9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-DnsCache { | |
<# | |
.Synopsis | |
Get entries from the DNS cache | |
#> | |
$Matches.Clear() | |
$DnsCache = (ipconfig /displaydns) -join "`r`n" | |
$Chunks = $DnsCache -split '\n\s*\r' | |
$Pattern = (New-Object System.Text.StringBuilder). | |
Append('Record Name[ \.]*: (?<RecordName>\S*)'). | |
Append('\s*'). | |
Append('Record Type[ \.]*: (?<RecordType>\S*)'). | |
Append('\s*'). | |
Append('Time To Live[ \.]*: (?<Ttl>\S*)'). | |
Append('\s*'). | |
Append('Data Length[ \.]*: (?<Length>\S*)'). | |
Append('\s*'). | |
Append('Section[ \.]*: (?<Section>\S*)'). | |
Append('\s*'). | |
Append('.+?Record[ \.]*: (?<Response>\S*)'). | |
ToString() | |
$DnsEntries = $Chunks | foreach { | |
if ($_ -match $Pattern) { | |
$Matches.Remove(0) | |
New-Object psobject -Property $Matches | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment