我怎样才能得到所有网络接口(包括未运行的)?接口、网络

2023-09-04 06:17:12 作者:男人无情便是王

我用这个code:

  NetworkInformation.NetworkInterface []接口= NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
 

以上code只能获取活动的网络连接,我需要所有的。我该怎么办呢? 提前致谢。 :)

解决方案

 使用System.Management;



    ManagementObjectSearcher查询=新ManagementObjectSearcher(
        SELECT * FROM Win32_NetworkAdapterConfiguration的);
    ManagementObjectCollection queryCollection = query.Get();

    的foreach(的ManagementObject莫queryCollection)
    {
        Console.WriteLine(莫[说明]的ToString());
    }
 

编辑:

面试问题 常用网络命令操 看准网

要查找所有其他[属性]的名称,改变的foreach是这样的:

 的foreach(的ManagementObject莫queryCollection)
            {

                的foreach(PropertyData PD在mo.Properties)
                {
                    Console.WriteLine(pd.Name);
                }
            }
 

I'm using this code:

NetworkInformation.NetworkInterface[] interfaces = NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();

the above code retrieving only the active network connections, I need of all. How I do this? Thanks in advance. :)

解决方案

using System.Management;   



    ManagementObjectSearcher query = new ManagementObjectSearcher(   
        "SELECT * FROM Win32_NetworkAdapterConfiguration" );   
    ManagementObjectCollection queryCollection = query.Get();   

    foreach (ManagementObject mo in queryCollection)   
    {   
        Console.WriteLine(mo["Description"].ToString());
    }   

Edit:

to find all others ["Properties"] name, change the foreach like this:

foreach (ManagementObject mo in queryCollection) 
            {

                foreach (PropertyData pd in mo.Properties)
                {
                    Console.WriteLine(pd.Name);
                }
            }