Skip to content

Instantly share code, notes, and snippets.

@techdecline
Created December 7, 2020 08:02
Show Gist options
  • Select an option

  • Save techdecline/b19fad4d546698d0e4f146dd31b9dc1e to your computer and use it in GitHub Desktop.

Select an option

Save techdecline/b19fad4d546698d0e4f146dd31b9dc1e to your computer and use it in GitHub Desktop.
Parse DNS Debug Log File and return PSCustomObject with given Property List
function Resolve-DnsLogEntry {
param (
[String]$DnsLogLine
)
$PropertyList = @{
Date = 0
Time = 1
ThreadID = 2
Context = 3
InternalPacketIdentifier = 4
UDPTCPIndicator = 5
SendReceiveIndicator = 6
RemoteIP = 7
Xid = 8
QueryResponseIndicator = 8
Opcode = 9
FlagsHex = 10
FlagsChar = 11
ResponseCode = 12
QuestionType = 13
QuestionName = 14
}
[string[]]$propertyKeys = $PropertyList.Keys
if ( $DnsLogLine -match "^\d{2}.*$") {
$dataSet = $DnsLogLine -split "\s+"
$returnObj = 1 | Select-Object -Property $propertyKeys
foreach ($prop in $propertyList.GetEnumerator()) {
$returnObj.$($prop.Key) = $dataSet[$prop.Value]
}
# sanitize Question Name
$returnObj.QuestionName = ($returnObj.QuestionName -replace "\(\d{1,}\)",".").TrimStart(".").TrimEnd(".")
return $returnObj
}
else {
return $null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment