有很多种方式,这里以 WMI 为例(项目需引用 System.Management):
using System;
using System.Management;
using System.Net;
public class Program
{
static void Main(string[] args)
{
try
{
string mac = string.Empty;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (mo["IPEnabled"].ToString() == "True")
{
mac = mo["MacAddress"].ToString();
}
}
string outPutStr = string.Format("MAC:{0}", mac);
Console.WriteLine(outPutStr);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
}
其他方式请参考:http://blog.csdn.net/yysyangyangyangshan/article/details/7091783