在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
项目需要:根据客户端信息去获取用户登录信息 1、根据客户端信息,并查询数据库是否有匹配。如果没有则重新插入客户端信息; 2、根据客户端的设置提交用户登录信息,用户登录成功后,查询以前是否有过配置信息,如果有这删除,保存最新信息; protected void Page_Load(object sender, EventArgs e) { Response.Write(GetMacAddress() + "<br />"); //C8:E7:D8:D5:E7:11 Response.Write(GetVolumeSerialNumber() + "<br />"); //5064B9C7 Response.Write(GetProcessorId() + "<br />"); //BFEBFBFF000306C3 Response.Write(GetMachineSerialNumber()); //BFEBFBFF000306C35064B9C7 } /// 获取网卡地址信息,如:C8:E7:D8:D5:E7:11 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; } } moc = null; mc = null; return mac; } catch (Exception ex) { return ex.Message; } } /// 取得设备硬盘序列号(卷标号),如:5064B9C7 public string GetVolumeSerialNumber() { try { ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid='c:'"); disk.Get(); return disk.GetPropertyValue("VolumeSerialNumber").ToString(); } catch(Exception ex) { return ex.Message; } } /// 获得CPU的序列号,如:BFEBFBFF000306C3 public string GetProcessorId() { try { string strCpu = null; ManagementClass myCpu = new ManagementClass("win32_Processor"); ManagementObjectCollection myCpuConnection = myCpu.GetInstances(); foreach (ManagementObject myObject in myCpuConnection) { strCpu = myObject.Properties["Processorid"].Value.ToString(); break; } return strCpu; } catch (Exception ex) { return ex.Message; } } /// 生成机器序列号,机器码 = CPU的序列号 + 硬盘序列号 public string GetMachineSerialNumber() { return string.Format("{0}{1}", GetProcessorId(), GetVolumeSerialNumber()); } 关于 ManagementClass 类,需要添加using System.Management; 命名空间,和.net System.Management引用; |
请发表评论