ASP.NET获取客户端MAC地址
程序员文章站
2023-10-27 21:44:46
///
/// get MacAddress...
/// <summary>
/// get MacAddress
/// </summary>
/// <returns></returns>
public static string GetMac()
{www.2cto.com
string MacAddress = String.Empty;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
MacAddress = mo["MacAddress"].ToString();
break;
}
}
moc = null;
mc = null;
// 将MAC地址用-分割
MacAddress = MacAddress.Replace(":", "-");
return MacAddress;
}
/// get MacAddress
/// </summary>
/// <returns></returns>
public static string GetMac()
{www.2cto.com
string MacAddress = String.Empty;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
MacAddress = mo["MacAddress"].ToString();
break;
}
}
moc = null;
mc = null;
// 将MAC地址用-分割
MacAddress = MacAddress.Replace(":", "-");
return MacAddress;
}