获得服务器硬件信息(CPUID、硬盘号、主板序列号、IP地址等)
1 // 注意:首先要在项目中添加引用 System.Management using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Management; public class Computer
{
public string CpuID; //CPU的ID
public int CpuCount; //CPU的个数
public string[] CpuMHZ;//CPU频率 单位:hz
public string MacAddress;//计算机的MAC地址
public string DiskID;//硬盘的ID
public string DiskSize;//硬盘大小 单位:bytes
public string IpAddress;//计算机的IP地址
public string LoginUserName;//操作系统登录用户名
public string ComputerName;//计算机名
public string SystemType;//系统类型
public string TotalPhysicalMemory; //总共的内存 单位:M
public string BoardID;// 主板序列号
public string BoardType;// 主板型号
private static Computer _instance;
public static Computer Instance()
{
if (_instance == null)
_instance = new Computer();
return _instance;
}
public Computer()
{
CpuID = GetCpuID();
CpuCount = GetCpuCount();
CpuMHZ = GetCpuMHZ();
MacAddress = GetMacAddress();
DiskID = GetDiskID();
DiskSize = GetSizeOfDisk();
IpAddress = GetIPAddress();
LoginUserName = GetUserName();
SystemType = GetSystemType();
TotalPhysicalMemory = GetTotalPhysicalMemory();
ComputerName = GetComputerName();
BoardID = GetBoardID();
BoardType = GetBoardType();
}
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
{
} }
public static int GetCpuCount()
{
try
{
using (ManagementClass mCpu = new ManagementClass("Win32_Processor"))
{
ManagementObjectCollection cpus = mCpu.GetInstances();
return cpus.Count;
}
}
catch
{
}
return -;
}
public static string[] GetCpuMHZ()
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection cpus = mc.GetInstances(); string[] mHz = new string[cpus.Count];
int c = ;
ManagementObjectSearcher mySearch = new ManagementObjectSearcher("select * from Win32_Processor");
foreach (ManagementObject mo in mySearch.Get())
{
mHz[c] = mo.Properties["CurrentClockSpeed"].Value.ToString();
c++;
}
mc.Dispose();
mySearch.Dispose();
return mHz;
}
public static string GetSizeOfDisk()
{
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moj = mc.GetInstances();
foreach (ManagementObject m in moj)
{
return m.Properties["Size"].Value.ToString();
}
return "-1";
}
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().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
{
} }
/// <summary>
/// 操作系统的登录用户名
/// </summary>
/// <returns> </returns>
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
{
} }
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
{
}
} string GetBoardID()
{
string strbNumber = string.Empty;
try
{
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_baseboard");
foreach (ManagementObject mo in mos.Get())
{
strbNumber = mo["SerialNumber"].ToString().Trim('.');
break;
}
}
catch (Exception ex)
{
strbNumber = "unknow";
} return strbNumber;
} /// <summary>
/// 主板型号
/// </summary>
/// <returns></returns>
string GetBoardType()
{
string st = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_BaseBoard");
foreach (ManagementObject mo in mos.Get())
{
st = mo["Product"].ToString();
}
return st;
} }
获得服务器硬件信息(CPUID、硬盘号、主板序列号、IP地址等)的更多相关文章
- PL/SQL 如何查看当前连接信息以及SQL PLUS如何指定IP地址
1.通过PL/SQL 想连接别的数据库可以通过在服务名前面加上IP和左斜线来实现: 2.有时我们的IP和左斜线不用输也能连别的数据库,是因为在一个文件里配置好了.这个文件在哪里? 在这个路径下的 NE ...
- 转: 通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
最近由于项目的需要,需要在程序中获取机器的硬盘序列号和MAC地址等信息,在C#下,可以很容易的获得这些信息,但是在C++程序中感觉比较麻烦.经过百度,发现很多大虾都是通过WMI来获取这些硬件信息的,网 ...
- (转)通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
最近由于项目的需要,需要在程序中获取机器的硬盘序列号和MAC地址等信息,在C#下,可以很容易的获得这些信息,但是在C++程序中感觉比较麻烦.经过百度,发现很多大虾都是通过WMI来获取这些硬件信息的,网 ...
- 【miscellaneous】如何利用硬盘号和CPU序列号为软件加密
原文:http://www.jiamisoft.com/blog/index.php/3469-yingpanhaocpuruanjianjiami.html 计算机软件是一种特殊的产品,为了防止软件 ...
- 通过WMI获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
转载:https://www.cnblogs.com/tlduck/p/5132738.html #define _WIN32_DCOM #include<iostream> #inclu ...
- python在windows下获取cpu、硬盘、bios、主板序列号
测试 此处使用的是wmi库,可以去google里面搜索“python wmi” import os, sysimport timeimport wmi,zlib def get_cpu_info() ...
- 获取Mac、CPUID、硬盘序列号、本地IP地址、外网IP地址OCX控件
提供获取Mac.CPUID.硬盘序列号.本地IP地址.外网IP地址OCX控件 开发语言:vc++ 可应用与WEB程序开发应用 <HTML><HEAD><TITLE> ...
- windows平台下获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
转自http://blog.csdn.net/jhqin/article/details/5548656,如有侵权,请联系本人删除,谢谢!! 头文件:WMI_DeviceQuery.h /* ---- ...
- JAVA获取计算机CPU、硬盘、主板、网络等信息
通过使用第三方开源jar包sigar.jar我们可以获得本地的信息 1.下载sigar.jar sigar官方主页 sigar-1.6.4.zip 2.按照主页上的说明解压包后将相应的文件copy到j ...
随机推荐
- WeiXinMPSDK-微信C# SDK
微信C# SDK 微信公众号:Senparc.Weixin.MP.dll 微信企业号:Senparc.Weixin.QY.dl 微信开放平台:Senparc.Weixin.Open.dll 本库为.N ...
- TreeMap源码解析
1.TreeMap介绍 TreeMap是一个通过红黑树实现有序的key-value集合. TreeMap继承AbstractMap,也即实现了Map,它是一个Map集合 TreeMap实现了Navig ...
- codeforces 652E Pursuit For Artifacts 边双连通分量
题意:n个点,m条边的无向图,有的边上有标记,每条边只能走一次 给你一个起点,一个终点,询问是否能找到从起点到终点的路径,这条路径至少包含一条含有标记的边 分析:然后边双缩点 下面介绍一下边双的性质 ...
- selenium 处理日期控件
今天遇到日期控件无法处理的问题,在北京-air的帮助下,看了下这篇blog http://www.cnblogs.com/Fskjb/archive/2011/10/27/2227111.html 根 ...
- APMServ5.2.6 + xdebug + notepad++调试环境配置
(原创文章,转载请注明出处:http://www.cnblogs.com/qzhforthelife/archive/2013/06/21/3147772.html) 刚整了两个多小时才把这个调试环境 ...
- 中断下半部-tasklet
http://edsionte.com/techblog/ tasklet的实现 tasklet(小任务)机制是中断处理下半部分最常用的一种方法,其使用也是非常简单的.正如在前文中你所知道的那样,一个 ...
- ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem
题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...
- vm虚拟机上安装apache+php+ftp+mysql
我在vm虚拟机上想安装 winxp和linux,然后在linux机上装apache+php+ftp+mysql,以下为我的按装过程: 1:连通虚拟机:两个虚拟机都选Host-Onl,查看主机Virt ...
- Weka 自动优化参数
import weka.core.*; import weka.classifiers.*; import weka.classifiers.meta.*; import weka.classifie ...
- 从源码剖析一个Spark WordCount Job执行的全过程
原文地址:http://mzorro.me/post/55c85d06e40daa9d022f3cbd WordCount可以说是分布式数据处理框架的”Hello World”,我们可以以它为 ...