ASP.NET獲取CPU序列號,硬碟序列號ID,獲取網路卡編號
using System;
using System.Management;
namespace Soyee.Comm
{
///
/// Computer Information
///
public class Computer
{
public string CpuID;
public string MacAddress;
public string DiskID;
public string IpAddress;
public string LoginUserName;
public string ComputerName;
public string SystemType;
public string TotalPhysicalMemory; //單位:M
private static Computer _instance;
public static Computer Instance()
{
if (_instance == null)
_instance = new Computer();
return _instance;
}
public Computer()
{
CpuID = GetCpuID();
MacAddress = GetMacAddress();
DiskID = GetDiskID();
IpAddress = GetIPAddress();
LoginUserName = GetUserName();
SystemType = GetSystemType();
TotalPhysicalMemory = GetTotalPhysicalMemory();
ComputerName = GetComputerName();
}
string GetCpuID()
{
try
{
//獲取CPU序列號程式碼
string cpuInfo = "";//cpu序列號
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
}
moc = null;
mc = null;
return cpuInfo;
}
catch
{
return "unknow";
}
finally
{
}
}
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
{
return "unknow";
}
finally
{
}
}
string GetIPAddress()
{
try
{
//獲取IP地址
string st = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
//st=mo["IpAddress"].ToString();
System.Array ar;
ar = (System.Array)(mo.Properties["IpAddress"].Value);
st = ar.GetValue(0).ToString();
break;
}
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
string GetDiskID()
{
try
{
//獲取硬碟ID
String HDid = "";
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)mo.Properties["Model"].Value;
}
moc = null;
mc = null;
return HDid;
}
catch
{
return "unknow";
}
finally
{
}
}
///
/// 作業系統的登入使用者名稱
///
///
string GetUserName()
{
try
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["UserName"].ToString();
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
///
/// PC型別
///
///
string GetSystemType()
{
try
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["SystemType"].ToString();
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
///
/// 實體記憶體
///
///
string GetTotalPhysicalMemory()
{
try
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["TotalPhysicalMemory"].ToString();
}
moc = null;
mc = null;
return st;
}
catch
{
return "unknow";
}
finally
{
}
}
///
///
///
///
string GetComputerName()
{
try
{
return System.Environment.GetEnvironmentVariable("ComputerName");
}
catch
{
return "unknow";
}
finally
{
}
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/631872/viewspace-921064/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 獲取網路卡MAC、硬碟序列號、CPU ID、BIOS編號(1) - 硬碟序列號 - 技術應用 - 豆豆網Mac硬碟iOS
- 在centos7下獲取 主機板 cpu 硬碟序列號CentOS硬碟
- 如何獲取BIOS序列號iOS
- 獲取SD卡序列號和廠商IDSD卡
- 教你用vbs指令碼獲取網路卡MAC,CPUID,硬碟序列號的實現程式碼指令碼MacUI硬碟
- 取得網路卡序列號 (轉)
- 如何獲取Android唯一標識(唯一序列號)Android
- 用api函式讀取硬碟的序列號 (轉)API函式硬碟
- 檢視硬碟序列號硬碟
- android 獲取手機號碼Android
- 用diskid.dll和disk32.dll獲得硬碟序列號 (轉)硬碟
- Mysql中獲取行號MySql
- 使用 JavaScript 獲取 table 行號和列號JavaScript
- win10 硬碟序列號怎麼查_win10系統如何查硬碟序列號Win10硬碟
- win10 查詢硬碟序列號方法 win10主機硬碟序列號怎麼看Win10硬碟
- 獲取app版本號相關資訊APP
- 間接獲取flash主版本號
- iphone獲取手機裝置號iPhone
- PHP根據身份證號碼,獲取性別、獲取生日、計算年齡、獲取地址、獲取生肖、獲取星座、以及判斷是否是身份證號(方法教程)PHP
- Android獲取聯絡人和電話號碼Android
- 查詢硬碟序列號的參考方案硬碟
- Android 實現省份城市的選擇,並獲取城市編號Android
- iOS裝置具體型號獲取iOS
- Java解析微信獲取手機號資訊Java
- IDEA實現序列號介面Idea
- 獲取網路卡 IP
- 蘋果官網序列號查詢蘋果
- 利用 Redis 生成序列號的功能實現編號自增Redis
- Android12以上獲取裝置網路訊號資料Android
- php 獲取微信公眾號access_tokenPHP
- iOS 獲取手機型號,XR,XS,MAXiOS
- PHP獲取QQ群成員QQ號碼PHP
- 前端實現微信公眾號授權—獲取openid前端
- SQL 獲取插入後的最新一條記錄ID號SQL
- Windows序列號集(轉)Windows
- 【題解】括號序列
- js獲取url傳遞引數,js獲取url?號後面的引數JS
- exonerate結果整理,獲取target序列