C# NetworkInterface.GetAllNetworkInterfaces方法()不';t匹配“中的所有结果”;ipconfig/all";

C# NetworkInterface.GetAllNetworkInterfaces方法()不';t匹配“中的所有结果”;ipconfig/all";,c#,wpf,C#,Wpf,所以问题在于,该方法返回的结果与使用cmd中的命令“ipconfig/all”得到的结果不同。有些适配器以正确的方式返回,但有些没有返回,并且信息丢失或不同。例如,ipconfig中的一些描述行与我的wpf程序中的描述行匹配,但有些不匹配或为空。我非常希望它能返回正确的DNS后缀、描述/名称和物理地址本身 主窗口 public partial class MainWindow : Window { public MainWindow() { Initialize

所以问题在于,该方法返回的结果与使用cmd中的命令“ipconfig/all”得到的结果不同。有些适配器以正确的方式返回,但有些没有返回,并且信息丢失或不同。例如,ipconfig中的一些描述行与我的wpf程序中的描述行匹配,但有些不匹配或为空。我非常希望它能返回正确的DNS后缀、描述/名称和物理地址本身

主窗口

public partial class MainWindow : Window
{

    public MainWindow()
    {
        InitializeComponent();
    }

    private void detectButton_Click(object sender, RoutedEventArgs e)
    {
        List<MacAddress> macAddresses = GetMacAddresses();


        for (int i = 1; i < macAddresses.Count; i++)
        {
            Label label = (Label)this.FindName("label" + i.ToString());

            label.Content = "Connection Specific DNS suffix: " + macAddresses[i].connectionSpecificDnsSuffix + Environment.NewLine
        + "Description: " + macAddresses[i].description + Environment.NewLine +
         "Physical Address: " + macAddresses[i].physicalAddress;
        }

        int count = 0;
        foreach (var item in macAddresses)
        {
            count += 1;
        }


    }

    internal List<MacAddress> GetMacAddresses()
    {
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
        List<MacAddress> macAdresses = new List<MacAddress>();
        foreach (NetworkInterface adapter in nics)
        {
            IPInterfaceProperties properties = adapter.GetIPProperties();
            MacAddress address = new MacAddress();
            address.connectionSpecificDnsSuffix = properties.DnsSuffix;
            address.description = adapter.Name;
            address.physicalAddress = adapter.GetPhysicalAddress().ToString();
            macAdresses.Add(address);
        }
        return macAdresses;
    }
编辑: cmd结果

返回的结果
您可能没有找到正确的地址。我建议使用foreach循环遍历每个MacAddress,并将它们动态添加到UI中


事实上,我试过了,而且成功了。你的循环方法是错误的。

很多东西被注册为“某种网络适配器”,而实际上并不是一个。我想到了蓝牙的全部功能。虚拟网络适配器instaleld也是虚拟机解决方案的一部分。仅仅从网络可用性检查中获取实际有用的信息是一项艰巨的工作:因此,您需要更具体地了解您期望的值和获得的值。如果其中任何一个实际上是物理网络适配器,我编辑了OP并添加了图片
for(int I=1
uh),我认为每个适配器都缺少一个地址
class MacAddress
{
    public string connectionSpecificDnsSuffix;
    public string description;
    public string physicalAddress;
}