首先添加对程序集System.Management的引用

  1. using System;  
  2. using System.Management;  
  3.   
  4. namespace ConsoleApplication1  
  5. {  
  6.     class Program  
  7.     {  
  8.         static void Main(string[] args)  
  9.         {  
  10.             ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");  
  11.             ManagementObjectCollection nics = mc.GetInstances();  
  12.             foreach (ManagementObject nic in nics)  
  13.             {  
  14.                 if (Convert.ToBoolean(nic["ipEnabled"]) == true)  
  15.                 {  
  16.                     Console.WriteLine((nic["IPAddress"as String[])[0]);  
  17.                     Console.WriteLine((nic["IPSubnet"as String[])[0]);  
  18.                     Console.WriteLine((nic["DefaultIPGateway"as String[])[0]);  
  19.                 }  
  20.             }  
  21.         }  
  22.     }  
  23. }  


相关文章:

  • 2021-12-29
  • 2022-01-16
  • 2022-02-09
  • 2021-09-25
  • 2021-12-04
  • 2021-12-20
猜你喜欢
  • 2021-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-02-22
  • 2021-09-06
  • 2021-11-20
  • 2021-09-22
相关资源
相似解决方案