Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created February 19, 2016 02:26
Show Gist options
  • Save chrisbrownie/84d5325ca5123e23f320 to your computer and use it in GitHub Desktop.
Save chrisbrownie/84d5325ca5123e23f320 to your computer and use it in GitHub Desktop.
Basics of parsing a Windows DNS Log file. Not good, but should be enough to jog the ol' memory.
$logFile = "dns2_cleaned.log"
$sr = New-Object System.IO.StreamReader($logFile)
$line = $sr.ReadLine()
$packets = @()
while ($line -ne $null) {
$line = $line -replace '\s+', ' '
$linebits = $line.Split(" ")
$packets += New-Object -TypeName PSObject -Property @{
"Protocol" = $linebits[6]
"Direction" = $linebits[7]
"Client" = $linebits[8]
"RecordType" = if ($linebits[10] -eq "R") { $linebits[16] } else { $linebits[14]}
}
$line = $sr.ReadLine()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment