-
Notifications
You must be signed in to change notification settings - Fork 0
/
HardInfo.cpp
90 lines (65 loc) · 2.24 KB
/
HardInfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ******************** HardInfo 1.1 ****************** */
/* Collect system information from x64 and x86 machines.
* MIT Licence.
* Compile using gcc 11.1 (https://gcc.gnu.org/)
* Created by Daniel Fros (Dec. 2022)
* */
#include <iostream>
#include <cpuid.h>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include "sys/sysinfo.h"
#include "sys/types.h"
#include <unistd.h>
#include <sys/utsname.h>
using namespace std;
string GetOperatingSystem_Name(){
#ifdef _WIN64
return "Windows 64-bit.";
#elif _WIN32
return "Windows 32-bit.";
#elif __APPLE__ || __MACH__
return "Mac OSX";
#elif __linux__
return "Linux";
#endif
}
int main() {
char CPUBrandString[0x40];
unsigned int CPUInfo[4] = {0,0,0,0};
__cpuid(0x80000000, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
unsigned int nExIds = CPUInfo[0];
memset(CPUBrandString, 0, sizeof(CPUBrandString));
for (unsigned int i = 0x80000000; i <= nExIds; ++i)
{
__cpuid(i, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
if (i == 0x80000002)
memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
else if (i == 0x80000003)
memcpy(CPUBrandString + 16, CPUInfo, sizeof(CPUInfo));
else if (i == 0x80000004)
memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
}
// string includes manufacturer, model and clockspeed.
cout << "HardInfo v1.1 - Written by Daniel Fros. MIT LICENCE. 2022." << endl;
cout << "\n" << endl;
cout << "=====================CPU======================" << endl;
cout << "CPU Type: " << CPUBrandString << endl;
cout << "\n" << endl;
// Get total system memory
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
long totalMem = pages * page_size;
int totalMemInMB = totalMem / 1024;
int totalMemInGB = totalMemInMB / 1024;
if(totalMemInGB > 8000 && totalMemInGB < 16000)
totalMemInGB = 8;
else if(totalMemInGB > 16000)
totalMemInGB = 16;
cout << "=====================MEMORY===================" << endl;
cout << "Total System Memory: " << totalMemInMB << " MB ~ " << totalMemInGB << " GB " << endl;
cout << "\n" << endl;
cout << "================OPERATING SYSTEM==============" << endl;
cout << GetOperatingSystem_Name() << endl;
}