使用C#代码获取cpu序列号、硬盘ID、网卡mac地址,供大家参考。
首先,添加引用System.Management。
完整代码:
//取得机器的CPU型号、硬盘ID、网卡MAC。
using System.Management;
using System.Management.Instrumentation;
private void GetInfo()
{
string cpuInfo = "";//cpu序列号
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
Response.Write ("cpu序列号:"+cpuInfo.ToString ());
}
//获取硬盘ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach(ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
Response.Write ("硬盘序列号:"+HDid.ToString ());
}
//获取网卡硬件地址
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach(ManagementObject mo in moc2)
{
if((bool)mo["IPEnabled"] == true)
Response.Write("MAC addresst{0}"+mo["MacAddress"].ToString());
mo.Dispose();
}
}
您可能感兴趣的文章:
如何获取远程机器的IP与MAC地址(c#代码)
asp.net根据MAC地址让每台电脑限领一次账号的代码
asp.net如何获取服务器ip与mac地址