码迷,mamicode.com
首页 > 系统相关 > 详细

获取mac地址

时间:2015-05-06 17:02:13      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
/// 获取本地IP
/// </summary>
/// <returns></returns>
public string GetIP()
{
IPHostEntry ipHost = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddr = ipHost.AddressList[0];
return ipAddr.ToString();
}
/// <summary>
/// 获取mac地址
/// </summary>
/// <returns></returns>
public string getMacAddr_Local()
{
string madAddr = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{
if (Convert.ToBoolean(mo["IPEnabled"]) == true)
{
madAddr = mo["MacAddress"].ToString();
madAddr = madAddr.Replace(‘:‘, ‘-‘);
}
mo.Dispose();
}
return madAddr;
}

获取mac地址

标签:

原文地址:http://www.cnblogs.com/yuanjiehot/p/4482362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!