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

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

相关文章:

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