반응형

WMI(Windows Management Instrumentation)를 이용해 컴퓨터의 모든 네트워크 어댑터를 확인해 보자.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
using System.Management;
 
 
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ListAllNetworkAdapters();
        }
 
        private static void ListAllNetworkAdapters()
        {
            ManagementObjectSearcher networkAdapterSearcher = new ManagementObjectSearcher("root\\cimv2""select * from Win32_NetworkAdapter");
            ManagementObjectCollection objectCollection = networkAdapterSearcher.Get();
 
            Console.WriteLine("There are {0} network adapaters:\n", objectCollection.Count);
 
            foreach (ManagementObject networkAdapter in objectCollection)
            {
                PropertyDataCollection networkAdapterProperties = networkAdapter.Properties;
                foreach (PropertyData networkAdapterProperty in networkAdapterProperties)
                {
                    if (networkAdapterProperty.Value != null)
                    {
                        Console.WriteLine("Network adapter property name: {0}", networkAdapterProperty.Name);
                        Console.WriteLine("Network adapter property value: {0}", networkAdapterProperty.Value);
                    }
                }
                Console.WriteLine("--------------------------------------------------------------------\n");
            }
        }
    }
}
 

 

소스를 입력하고 빌드한다.

 

내 컴퓨터에서는 16개의 네트워크 어댑터를 찾았다.

 

반응형
Posted by J-sean
: