NIC speed / duplex based on a named interface

(imported topic written by MrFixit)

I gotten to the point my head hurts with this one and was wondering if the true Guru’s out there and get me past my mental block.

The goal is to report the speed and duplex for a NIC, and of course being dynamic enough to support the couple different vendors which of course store the information differently in the registry.

The NIC I’m looking for values from has been named ‘Public’

First relevance returns to me the InstanceID of the NIC that I’m interested in.

q: (values whose (exists name of it AND (name of it = “SpeedDuplex” OR name of it = “RequestedMediaType”)) of it) of keys whose (exists value “NetCfgInstanceID” of it AND value “NetCfgInstanceID” of it as string contains ((name of it) of adapter whose (friendly name of it as lowercase = “public”) of network)) of keys “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” of registry

A: 0

Second relevance is what I would like grab the enumerated value of that particular NIC but the fixed value of “0” and not what might actually be configured.

q: value “0” of keys ((following text of first “||” of it) of (concatenation “||” of ((item 0 of it as string; “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” & item 1 of it & “\Ndi\params” & name of item 0 of it & “\enum” ) of (values whose (exists name of it AND (name of it = “SpeedDuplex” OR name of it = “RequestedMediaType”)) of it, name of it) of keys whose (exists value “NetCfgInstanceID” of it AND value “NetCfgInstanceID” of it as string contains ((name of it) of adapter whose (friendly name of it as lowercase = “public”) of network)) of keys “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” of registry))) of registry

A: Auto-negotiate 1000Mbps

This next relevance is the complete enumerated table for the targeted interface. Of course this can vary with the model of the NIC so I would prefer to look this up vs. using a static table.

q: (name of it, it) of values of keys ((following text of first “||” of it) of (concatenation “||” of ((item 0 of it as string; “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” & item 1 of it & “\Ndi\params” & name of item 0 of it & “\enum” ) of (values whose (exists name of it AND (name of it = “SpeedDuplex” OR name of it = “RequestedMediaType”)) of it, name of it) of keys whose (exists value “NetCfgInstanceID” of it AND value “NetCfgInstanceID” of it as string contains ((name of it) of adapter whose (friendly name of it as lowercase = “public”) of network)) of keys “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” of registry))) of registry

A: 0, Auto Detect

A: 1, 10Mbps/Half Duplex

A: 2, 10Mbps/Full Duplex

A: 3, 100Mbps/Half Duplex

A: 4, 100Mbps/Full Duplex

A: 5, Auto-negotiate 1000Mbps

Also embedded into that prior relevance is the instance but I can’t seem to find a way to “replace” the key and the value at the same time to get the result that I’m looking for.

q: (concatenation “||” of ((item 0 of it as string; “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” & item 1 of it & “\Ndi\params” & name of item 0 of it & “\enum” ) of (values whose (exists name of it AND (name of it = “SpeedDuplex” OR name of it = “RequestedMediaType”)) of it, name of it) of keys whose (exists value “NetCfgInstanceID” of it AND value “NetCfgInstanceID” of it as string contains ((name of it) of adapter whose (friendly name of it as lowercase = “public”) of network)) of keys “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” of registry))

A: 5||HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}\0012\Ndi\params\SpeedDuplex\enum

(imported comment written by MrFixit)

I got a idea last night when sleeping on this and applied a look up table approach to it and got the result I was looking for. Looks pretty wild and I wonder if there are better ways or if this can be improved on. Any ideas?

q: (if (exists (it,((name of it as integer, it as string) of values of keys ((following text of first “||” of it) of (concatenation “||” of ((item 0 of it as string; “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” & item 1 of it & “\Ndi\params” & name of item 0 of it & “\enum” ) of (values whose (exists name of it AND (name of it = “SpeedDuplex” OR name of it = “RequestedMediaType”)) of it, name of it) of keys whose (exists value “NetCfgInstanceID” of it AND value “NetCfgInstanceID” of it as string contains ((name of it) of adapter whose (friendly name of it as lowercase = “public”) of network)) of keys “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” of registry))) of registry)) whose (item 0 of it = item 0 of item 1 of it)) then (item 1 of item 1 of (it,((name of it as integer, it as string) of values of keys ((following text of first “||” of it) of (concatenation “||” of ((item 0 of it as string; “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” & item 1 of it & “\Ndi\params” & name of item 0 of it & “\enum” ) of (values whose (exists name of it AND (name of it = “SpeedDuplex” OR name of it = “RequestedMediaType”)) of it, name of it) of keys whose (exists value “NetCfgInstanceID” of it AND value “NetCfgInstanceID” of it as string contains ((name of it) of adapter whose (friendly name of it as lowercase = “public”) of network)) of keys “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” of registry))) of registry)) whose (item 0 of it = item 0 of item 1 of it)) else it as string) of ((item 0 of it as integer) of (values whose (exists name of it AND (name of it = “SpeedDuplex” OR name of it = “RequestedMediaType”)) of it, name of it) of keys whose (exists value “NetCfgInstanceID” of it AND value “NetCfgInstanceID” of it as string contains ((name of it) of adapter whose (friendly name of it as lowercase = “public”) of network)) of keys “HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}” of registry)

A: Auto Detect

T: 97.142 ms

I: plural string