【问题标题】:C# performance counter and nic nameC# 性能计数器和 nic 名称
【发布时间】:2012-06-20 15:56:56
【问题描述】:

与 ipconfig/all 和 c# 系统调用相比,perfmon 计数器使用不同的 NIC 名称,如下所示(来自 ipconfig/all)

   Ethernet adapter HHHH:       

   Connection-specific DNS Suffix  . :   

   Description . . . . . . . . . . . : HP NC364T PCIe Quad Port Gigabit Server Adapter #3
   Physical Address. . . . . . . . . : 00-1F-29-0D-26-59
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 166.49.47.10(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.240
   Default Gateway . . . . . . . . . :
   NetBIOS over Tcpip. . . . . . . . : Disabled
using System.Net.NetworkInformation;
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();

我收到HP NC364T PCIe Quad Port Gigabit Server Adapter #3。与 ipconfig 完全相同。 但是 perfmon 使用HP NC364T PCIe Quad Port Gigabit Server Adapter _3(下划线而不是哈希)。我是否必须使用不同的调用来获得与 perfmon 具有的完全相同的计数器名称?如果有,是什么?

【问题讨论】:

  • 你也可以使用 WMI 获得"HP NC364T PCIe Quad Port Gigabit Server Adapter #3"

标签: c# networking performancecounter


【解决方案1】:

我个人会使用注册表以本地方式列出网络设备。 有许多不同的方式来检索信息,但不是所有的方式都显示 像系统一样的信息。 可能的代码示例可能如下所示(未完全处理错误)。 它适用于 Windows Vista 32/64 位和 7。 它与 NET 类有很大不同,但它认为它的作用相同。 必须添加命名空间“使用 Microsoft.Win32”才能运行代码。

private void button1_Click(object sender, EventArgs e)
    {
        ListPCIDevices(false, listBox1);
    }

    public static void ListPCIDevices(bool ListOnlyNetworkDevices, ListBox LB)
    {
        string NetKey = @"SYSTEM\ControlSet001\Enum\PCI";
        using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(NetKey))
        {
            foreach (string skName in rk.GetSubKeyNames())
            {
                using (RegistryKey sk = rk.OpenSubKey(skName))
                {

                    foreach (string skSubName in sk.GetSubKeyNames())
                    {

                        using (RegistryKey ssk = sk.OpenSubKey(skSubName))
                        {

                            object ItemName = ssk.GetValue("DeviceDesc");
                            object ItemCat = ssk.GetValue("Class");
                            if (ItemCat == null) { ItemCat = "Unknown"; }

                            if ((ItemName != null) && ((ItemCat.ToString() == "Net")||(!ListOnlyNetworkDevices)))
                            {
                                LB.Items.Add(ItemName.ToString().Split(';')[1]);
                            }

                        }
                    }
                }
            }
        }
    }

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 2011-01-07
    • 1970-01-01
    相关资源
    最近更新 更多