首页 > 代码库 > c#获取电脑内部信息
c#获取电脑内部信息
/// <summary>
/// 得到电脑CPU序列号
/// </summary>
public string GetComputerCPUSerialNo()
{
string cpuSerialNo = string.Empty;
System.Management.ManagementClass managementClass = new System.Management.ManagementClass("Win32_Processor");
System.Management.ManagementObjectCollection managementObjectCollection = managementClass.GetInstances();
foreach (System.Management.ManagementObject managementObject in managementObjectCollection)
{
cpuSerialNo = managementObject.Properties["ProcessorId"].Value.ToString();
break;
}
return cpuSerialNo;
}
/// <summary>
/// 得到客户端IP地址
/// </summary>
public string GetClientIdAddress()
{
string ip = string.Empty;
try
{
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null)
ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
else
ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString();
if (string.IsNullOrEmpty(ip)) {
ip = System.Web.HttpContext.Current.Request.UserHostAddress;
}
}
catch { ip = "1.1.1.1"; }
return ip;
}