标签:
/// <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;
}
标签:
原文地址:http://www.cnblogs.com/yuanjiehot/p/4482362.html