using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace consolemac
{
class Program
{
static void Main(string[] args)
{
string strMac = string.Empty;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); //获取网络信息
ManagementObjectCollection moc = mc.GetInstances(); //取网卡配置信息
foreach(ManagementObject mo in moc)
{ //读取MAC地址
if ((bool)mo["IPEnabled"]==true)
{
Console.WriteLine("MAC地址为:");
strMac = mo["MacAddress"].ToString();
Console.WriteLine(strMac);
}
}
Console.ReadLine();
}
}
}