/// <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;
}