c# 获取Ip网关方法2

要加入mengment的引用在.net框架中。

主要代码:

  ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection nics = mc.GetInstances();
            foreach (ManagementObject nic in nics)
              {
                if (Convert.ToBoolean(nic["ipEnabled"]) == true)
                {
                    this.textBox1.Text = (nic["IPAddress"] as string[])[0];
                    this.textBox2.Text = (nic["IPSubnet"]   as  string[])[0];
                    this.textBox3.Text = (nic["DefaultIPGateway"] as string[])[0];
                  
                   }
                }

         

你可能感兴趣的:(C#)