C# 性能计数器和 nic 名称

标签 c# networking performancecounter

与 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 四端口千兆服务器适配器 #3。与 ipconfig 完全相同。 但是 perfmon 正在使用HP NC364T PCIe 四端口千兆服务器适配器_3(下划线而不是井号)。我是否必须使用不同的调用来获得与 perfmon 所具有的完全相同的计数器名称?如果有,那是什么?

最佳答案

我个人会使用注册表以 native 方式列出网络设备。 检索信息的方式有很多种,但并不是所有的方式都显示 像系统一样的信息。 可能的代码示例可能如下所示(未完全处理错误)。 它适用于 Windows Vista 32/64 位和 7。 它与 NET 类有很大不同,但它认为它的作用相同。 必须添加命名空间“using 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]);
                            }

                        }
                    }
                }
            }
        }
    }

关于C# 性能计数器和 nic 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11123450/

相关文章:

c# - 在 C# 中执行 SQL 语句?

c# - StringBuilder.ToString() 的复杂性是什么

performance - Postgresql 通过网络发送查询结果非常慢

java - ServerSocket 不接受 droid 模拟器

.net - 如何在 IIS 中使用性能计数器和 WCF 服务?

c# - NHibernate future 与 CreateMultiCriteria

c# - Windows 的声音管理器类

image - flutter : Display Local Image when Network Image not found or error fetching it?

c# - 性能计数器的使用

c# - 即使在删除性能类别后,RawFraction 性能计数器仍保持其状态