Skip to content

Instantly share code, notes, and snippets.

@indented-automation
Created July 12, 2022 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indented-automation/ea324c2b423bfc95554dc40cf2e3c051 to your computer and use it in GitHub Desktop.
Save indented-automation/ea324c2b423bfc95554dc40cf2e3c051 to your computer and use it in GitHub Desktop.
A partial parser for DHCP options in Windows
function Get-DhcpClientOption {
[CmdletBinding()]
param ( )
$adapters = Get-CimInstance Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE AND DhcpEnabled=TRUE'
foreach ($adapter in $adapters) {
$params = @{
LiteralPath = Join-Path 'HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces' -ChildPath $adapter.SettingID
Name = 'DhcpInterfaceOptions'
}
$dhcpInterfaceOptions = Get-ItemPropertyValue @params
$reader = [System.IO.BinaryReader][System.IO.MemoryStream][Byte[]]$dhcpInterfaceOptions
do {
$code, $null = $reader.ReadBytes(8)
$length, $null = $reader.ReadBytes(4)
$vendor, $null = $reader.ReadBytes(4)
$null = $reader.ReadBytes(4)
$value = $reader.ReadBytes($length)
[PSCustomObject]@{
Code = $code
Length = $length
Vendor = $vendor
Value = $value
}
} while ($reader.BaseStream.Position -lt $reader.BaseStream.Length)
$reader.Dispose()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment