標籤:c#擷取電腦內部資訊 得到電腦cpu序號 得到用戶端ip地址 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;
}