IPv6 Link local addresses and device identifier

Tags:
If I run ipconfig on my system the partial results are this
Wireless LAN adapter Wireless Network Connection:
Connection-specific DNS Suffix . : tiscali.co.uk
Link-local IPv6 Address . . . . . : fe80::6d95:b824:6a72:a0a9%11
IPv4 Address. . . . . . . . . . . : 192.168.1.2
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::4547:ee51:7aac:521e%10
IPv4 Address. . . . . . . . . . . : 10.10.54.202
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Notice that the IPv6 addresses have a % sign followed by a number. This is the device id of the network adapter
If we modify our get-IPAddress function to output the adapter’s deviceid (Index on Win32_NetworkAdapterConfiguration class)
function get-IPAddress { [CmdletBinding()] param ( [string]$computer="$env:COMPUTERNAME" ) Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computer | where {$_.IPAddress} | foreach { $address = $_.IPAddress[1] Write-Debug "Test for ::" if ($_.IPAddress[1].Contains("::")){ $blocks = $_.IPAddress[1] -split ":" $count = $blocks.Count $replace = 8 - $count + 1 for ($i=0; $i -le $count-1; $i++){ if ($blocks[$i] -eq ""){ $blocks[$i] = ("0000:" * $replace).TrimEnd(":") } } $address = $blocks -join ":" } Write-Debug "Check leading 0 in place" $blocks = $address -split ":" for ($i=0; $i -le $blocks.Count-1; $i++){ if ($blocks[$i].length -ne 4){ $blocks[$i] = $blocks[$i].Padleft(4,"0") } } $address = $blocks -join ":" $ipconfig = New-Object -TypeName PSObject -Property @{ Description = $($_.Description) IPv4Address = $($_.IPAddress[0]) IPv4Subnet = $($_.IPSubnet[0]) IPv6Address = $address IPv6Subnet = $($_.IPSubnet[1]) DeviceId = $($_.Index) } | select Description, IPv4Address, IPv4Subnet, IPv6Address, IPv6Subnet, DeviceId $ipconfig } }
we get this output
PS> get-IPAddress
Description : NVIDIA nForce 10/100/1000 Mbps Networking Controller
IPv4Address : 10.10.54.202
IPv4Subnet : 255.255.255.0
IPv6Address : fe80:0000:0000:0000:4547:ee51:7aac:521e
IPv6Subnet : 64
DeviceId : 7
Description : Atheros AR5007 802.11b/g WiFi Adapter
IPv4Address : 192.168.1.2
IPv4Subnet : 255.255.255.0
IPv6Address : fe80:0000:0000:0000:6d95:b824:6a72:a0a9
IPv6Subnet : 64
DeviceId : 11
These device ids don’t match – whats going on.
If we use the MSNdis_EnumerateAdapter and MSNdis_EnumerateAdapterEX classes as in this function from http://msmvps.com/blogs/richardsiddaway/archive/2011/08/25/network-adapter-details.aspx
We can get the adapter details stored in the registry which uses a different set of indexes!!!
function get-adapter { param( [string]$computer="." ) Get-WmiObject -Namespace root\wmi -Class MSNdis_EnumerateAdapter ` -ComputerName $computer | foreach { $nic = Get-WmiObject -Namespace root\wmi -Class MSNdis_EnumerateAdapterEx ` -ComputerName $computer -Filter "InstanceName = '$($_.InstanceName)'" $header = $nic.EnumerateAdapter.Header New-Object -TypeName PSobject -Property @{ Computer = $_.__SERVER Adapter = $_.InstanceName Device = $_.DeviceName Active = $_.Active Index = $($nic.EnumerateAdapter.IfIndex) NetLuid = $($nic.EnumerateAdapter.NetLuid) Revision = $header.Revision Size = $header.Size Type = $header.Type } } }
get-adapter | sort Index | Format-Table adapter, Index –AutoSize
produces (truncated output of)
Adapter Index
——- —–
NVIDIA nForce 10/100/1000 Mbps Networking Controller 10
Atheros AR5007 802.11b/g WiFi Adapter 11
which matches the ipconfig results of
Ethernet adapter Local Area Connection:
Link-local IPv6 Address . . . . . : fe80::4547:ee51:7aac:521e%10
Wireless LAN adapter Wireless Network Connection:
Link-local IPv6 Address . . . . . : fe80::6d95:b824:6a72:a0a9%11
We can test the relationship between the registry and WMI device Ids
function resolve-deviceID { [CmdletBinding()] param ( [string]$computer="$env:COMPUTERNAME" ) Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computer | where {$_.IPAddress} | foreach { $nic = Get-WmiObject -Namespace root\wmi -Class MSNdis_EnumerateAdapterEx ` -ComputerName $computer -Filter "InstanceName = '$($_.Description)'" New-Object -TypeName PSObject -Property @{ Name = $($_.Description) WMI_Index = $($_.Index) Reg_Index = $($nic.EnumerateAdapter.IfIndex) } } }
Which produces this output
PS> resolve-deviceid | ft -a
Name Reg_Index WMI_Index
—- ——— ———
NVIDIA nForce 10/100/1000 Mbps Networking Controller 10 7
Atheros AR5007 802.11b/g WiFi Adapter 11 11
 Comment on this Post