日期:2014-05-18  浏览次数:20485 次

怎么获取本机MAC地址
获取 客户端MAC地址. 不是服务器端MAC 地址. 怎么写.

------解决方案--------------------
#region 获取客户机硬件信息
/// <summary>
/// 获取cpu序列号
/// </summary>
/// <returns></returns>
public static string GetCpuID()
{
try
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null;
foreach (ManagementObject mo in moc)
{
strID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strID;
}
catch
{
return "";
}
}
/// <summary>
/// 获取硬盘编号
/// </summary>
/// <returns></returns>
public static string GetHardDiskNum()
{
try
{
ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null;
foreach (ManagementObject mo in moc)
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
return strID;
}
catch
{
return "";
}

}

/// <summary>
/// 获取网卡Mac地址
/// </summary>
/// <returns></returns>
public static string GetMacAddress()
{
try
{

string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
mac = mo["MacAddress"].ToString();
break;
}
}
return mac;
}
catch
{
return "";
}
}
/// <summary>
/// 获取主板编号
/// </summary>
/// <returns></returns>
public static string GetBoardID()
{
try
{
ManagementClass mc = new ManagementClass("Win32_BaseBoard");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null;
foreach (ManagementObject mo in moc)
{
strID = mo.Properties["SerialNumber"].Value.ToString();
break;
}
return strID;
}
catch
{
return "";
}
}
------解决方案--------------------
调用win32 API 或者WMI就可以实现了。
放在服务器上出错,可能是由于系统版本或者权限设置,系统配置的原因
希望这篇文章能够帮助到你http://www.cnblogs.com/liufei88866/archive/2010/05/11/1732671.html

------解决方案--------------------
C# code

    public static string GetMACAddresses()    //获取网卡地址
    {
        try
        {