Get all IPs, subnet masks of this unit, and the default gateway

xiaoxiao2021-03-06  39

Add reference to System.Management

Using system.management ;. . . // Get IP, subnet mask (subnet mask), and default gateway ManagementClass mc = new ManagementClass ( "Win32_NetworkAdapterConfiguration"); ManagementObjectCollection nics = mc.GetInstances (); foreach (ManagementObject nic in nics) {if (Convert.ToBoolean ( NIC ["iPenabled"]) == True) {Console.writeline ((NIC [ipaddress "] as string []) [0]); console.writeline ((NIC [" IPSUBNET "] as string []) [ 0]); console.writeLine ((NIC ["" "" ""] as string []) [0]);}}. . .

If you need other information, please refer to Platform SDK: Windows Management Instrumentation

转载请注明原文地址:https://www.9cbs.com/read-75804.html

New Post(0)