首页 新闻 搜索 专区 学院

SNMP抓取服务器或本机信息(如:内存,cpu,温度,硬盘)

1
悬赏园豆:50 [已解决问题] 解决于 2012-10-23 09:09
< >
分享
最佳答案
0
 1 public class GetUserInfo
 2     {
 3         public static string GetCPU()
 4         {
 5             string cpuInfo = "";//cpu序列号  
 6             ManagementClass cimobject = new ManagementClass("Win32_Processor");
 7             ManagementObjectCollection moc = cimobject.GetInstances();
 8             foreach (ManagementObject mo in moc)
 9             {
10                 cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
11                 //  Response.Write ("cpu序列号:"+cpuInfo.ToString ());  
12             }
13             return cpuInfo;
14         }
15 
16         public static string GetHardDisk()
17         {
18             string HDid = string.Empty;
19             ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
20             ManagementObjectCollection moc1 = cimobject1.GetInstances();
21             foreach (ManagementObject mo in moc1)
22             {
23                 HDid = (string)mo.Properties["Model"].Value;
24                 //Response.Write ("硬盘序列号:"+HDid.ToString ()); 
25                 
26             }
27             return HDid;
28         }
29 
30 
31         public static string GetRealIp()
32         {
33             string ip = "";
34             try
35             {
36                 HttpRequest request = HttpContext.Current.Request;
37 
38                 if (request.ServerVariables["http_VIA"] != null)
39                 {
40                     ip = request.ServerVariables["http_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
41                 }
42                 else
43                 {
44                     ip = request.UserHostAddress;
45                 }
46             }
47             catch (Exception e)
48             {
49                 throw e;
50             }
51 
52             return ip;
53         }
54     }

这个只是获取系统信息的一部分代码,获取都差不多的。

收获园豆:50
雨之秋水 | 小虾三级 |园豆:647 | 2012-10-19 15:11
其他回答(1)
0

要不要别人帮你把工资给领了

az235 | 园豆:8283 (大侠五级) | 2012-10-19 13:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册