Joh*_*ann 7 c# networking performancecounter
perfmon计数器使用不同的NIC名称与ipconfig/all和c#系统调用相比,如下所示(这是来自ipconfig/all)
Run Code Online (Sandbox Code Playgroud)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();
Run Code Online (Sandbox Code Playgroud)
我得到HP NC364T PCIe Quad Port Gigabit Server Adapter #3
.与ipconfig完全相同.
但是 perfmon正在使用HP NC364T PCIe Quad Port Gigabit Server Adapter _3
(下划线而不是哈希).我是否必须使用不同的调用来获得与perfmon相同的计数器名称?如果是这样,它是什么?
我个人会使用注册表以本机方式列出网络设备。检索信息的方式有很多种,但并非所有方式都像系统那样显示信息。可能的代码示例可能如下所示(未完全处理错误)。它适用于 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]);
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
814 次 |
最近记录: |