How to query specific adapters in Win32_PerfFormattedData_Tcpip_NetworkInterface?

随声附和 提交于 2019-12-12 17:08:31

问题


How can I query specific adapters (ideally based on the IP address) from Win32_PerfFormattedData_Tcpip_NetworkInterface? I've spent a while googling this issue, but I didn't come up with a solution.

I tried using Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration, however, I cannot link these to the performance data.

As I happen to have more than one network adapter on certain systems I cannot differentiate which adapter the returned values belong to - any ideas?


回答1:


            ConnectionOptions connection = new ConnectionOptions();
            ManagementScope scope = new ManagementScope("\\root\\CIMV2", connection);
            scope.Connect();

            ObjectQuery query = new ObjectQuery(
                "SELECT * FROM Win32_PerfFormattedData_Tcpip_NetworkInterface");

            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope, query);

            foreach (ManagementObject queryObj in searcher.Get())
            {
                Console.WriteLine("Name: {0}", queryObj["Name"]);
                Console.WriteLine("Current Bandwidth: {0}", queryObj["CurrentBandwidth"]);
            }

My output was

Name: Realtek PCIe GBE Family Controller - Packet Scheduler Miniport Current Bandwidth: 100000000 Name: MS TCP Loopback interface Current Bandwidth: 10000000 Press any key to continue . . .

Similar to this you can enhance the properties of this Win32_ class




回答2:


Here is how I did it.

  1. Query for the instances of Win32_NetworkAdapter that you are interested in.
  2. Take the value of 'PNPDeviceID' from each Win32_NetworkAdapter and append it to "\HKLM\SYSTEM\CurrentControlSet\Enum\" to produce a registry path to information on the adapter. Here is an example: "\HKLM\SYSTEM\CurrentControlSet\Enum\PCI\VEN_8086&DEV_100E&SUBSYS_001E8086&REV_02\3&267A616A&0&18".
  3. Query the registry for the "FriendlyName" key at the path you derived above.
  4. If the "FriendlyName" key is present then take its string value. If the "FriendlyName" key is not defined then instead use the value of the "Description" key from Win32_NetworkAdapter.
  5. Take the string you got in step #4 and replace all instances of "/" and "#" with an underscore "_".
  6. The resulting string from step #5 should match the "Name" property within Win32_PerfFormattedData_Tcpip_NetworkInterface.


来源:https://stackoverflow.com/questions/3813937/how-to-query-specific-adapters-in-win32-perfformatteddata-tcpip-networkinterface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!