Created
July 12, 2022 15:43
-
-
Save indented-automation/ea324c2b423bfc95554dc40cf2e3c051 to your computer and use it in GitHub Desktop.
A partial parser for DHCP options in Windows
This file contains hidden or 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-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