?
?
static void Main(string[] args) { string mac=null,ip=null,ipsubnet=null,ipgateway=null,ipport=null; ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection nics = mc.GetInstances(); foreach (ManagementObject nic in nics) { if ((nic["DefaultIPGateway"] as String[]) != null && Convert.ToBoolean(nic["ipEnabled"]) == true) { mac = nic["MacAddress"].ToString();//Mac地址 ip = (nic["IPAddress"] as String[])[0];//IP地址 ipsubnet = (nic["IPSubnet"] as String[])[0];//子網(wǎng)掩碼 ipgateway = (nic["DefaultIPGateway"] as String[])[0];//默認(rèn)網(wǎng)關(guān) } } Console.WriteLine(mac); Console.WriteLine(ip); Console.WriteLine(ipsubnet); Console.WriteLine(ipgateway); Console.ReadKey(); }
?
本文摘自 :https://www.cnblogs.com/