首先找到资源管理器里的引用,右击添加引用: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-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2021-08-25
  • 2021-04-01
  • 2021-08-12
猜你喜欢
  • 2021-06-11
  • 2021-07-07
  • 2022-12-23
  • 2021-12-10
  • 2022-02-09
  • 2021-10-09
相关资源
相似解决方案