C # obtain hardware and operating system information

Source: Internet
Author: User
[Shocking release] baimu cracking-IP proxy software V1.0.0.0
Http://www.bmpj.net/thread-1743-1-1.html
1 using System;
2 using System. Collections. Generic;
3 using System. Text;
4 using System. Management;
5
6 namespace MonitorSoftware
7 {
8 internal class Computer
9 {
10 internal static string CPUName
11 {
12 get
13 {
14 string cpuinfo = "unknow ";
15 ManagementClass mc = new ManagementClass ("win32_processor ");
16 ManagementObjectCollection moc = mc. GetInstances ();
17
18 foreach (ManagementObject mo in moc)
19 {
20 cpuinfo = mo ["Name"]. ToString ();
21}
22 moc. Dispose ();
23 return cpuinfo;
24}
25}
26
27 private static string CPUSN
28 {
29 get
30 {
31 string sn = ""; // cpu serial number
32 ManagementClass cimobject = new ManagementClass ("Win32_Processor ");
33 ManagementObjectCollection moc = cimobject. GetInstances ();
34 foreach (ManagementObject mo in moc)
35 {
36 sn = mo. Properties ["ProcessorId"]. Value. ToString ();
37}
38 return sn;
39}
40}
41
42 private static string HardDiskID
43 {
44 get
45 {
46 string hdid = "";
47 ManagementClass cimobject1 = new ManagementClass ("Win32_DiskDrive ");
48 ManagementObjectCollection moc1 = cimobject1.GetInstances ();
49 foreach (ManagementObject mo in moc1)
50 {
51 hdid = mo. Properties ["Model"]. Value. ToString ();
52}
53
54 return hdid;
55}
56}
57
58 internal static string MAC
59 {
60 get
61 {
62 string mac = "unknow ";
63 ManagementClass mAdapter = new ManagementClass ("Win32_NetworkAdapterConfiguration ");
64 ManagementObjectCollection moc = mAdapter. GetInstances ();
65 foreach (ManagementBaseObject mo in moc)
66 {
67 if (bool) mo ["IpEnabled"] = true)
68 {
69 mac = mo ["MacAddress"]. ToString ();
70}
71}
72 moc. Dispose ();
73 return mac;
74}
75
76}
77
78 internal static string MemorySize
79 {
80 get
81 {
82 ManagementClass mc = new ManagementClass ("Win32_OperatingSystem ");
83 ManagementObjectCollection moc = mc. GetInstances ();
84 double sizeAll = 0.0;
85 foreach (ManagementObject mo in moc)
86 {
87 if (mo. Properties ["TotalVisibleMemorySize"]. Value! = Null)
88 {
89 sizeAll + = Convert. ToDouble (mo. Properties ["TotalVisibleMemorySize"]. Value. ToString ());
90}
91}
92 // sizeAll // = 1000000;
93 moc. Dispose ();
94 return sizeAll. ToString ("0 .###");
95}
96
97}
98
99 internal static string [] IPAddress
100 {
101 get
102 {
103 string hostname = System. Net. Dns. GetHostName ();
104 System. Net. IPHostEntry ipEntry = System. Net. Dns. GetHostEntry (hostname );
105 string [] ips = new string [ipEntry. AddressList. Length];
106 for (int I = 0; I <ipEntry. AddressList. Length; I ++)
107 {
108 ips [I] = ipEntry. AddressList [I]. ToString ();
109}
110 return ips;
111}
112}
113
114 internal static string OSType
115 {
<Span style = "color %

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.