-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
189 lines (169 loc) · 5.28 KB
/
Copy pathmain.cpp
File metadata and controls
189 lines (169 loc) · 5.28 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include<iostream>
#include<windows.h>
#include<stdio.h>
#include<tchar.h>
#include<ctime>
#include<cstdlib>
#include<wininet.h>
#include<typeinfo>
#include<iphlpapi.h>
#include<ctime>
#pragma comment(lib,"wininet.lib")
#define UNLEN 256
#define UNCLEN 256
#define DIV 1024
#define WIDTH 7
//-----------------------------------------------------------------------------
void get_username()
{
std:: cout << "-------------------------" << std::endl;
TCHAR user[UNLEN+1];
DWORD user_len = UNLEN+1;
GetUserName((TCHAR*)user, &user_len);
std::cout << "User: " << user << std::endl;
std::cout << "Last login: " << __TIME__ << std::endl;
std::cout << "--------------------------" << std::endl;
}
//-----------------------------------------------------------------------------
void get_compname()
{
TCHAR comp[UNCLEN+1];
DWORD comp_len = UNCLEN+1;
GetComputerName((TCHAR*)comp, &comp_len);
std::cout << "Machine Name: " << comp << std::endl;
}
//-----------------------------------------------------------------------------
void get_version()
{
DWORD dwVersion = 0;
DWORD dwMajorVersion = 0;
DWORD dwMinorVersion = 0;
DWORD dwBuild = 0;
dwVersion = GetVersion();
dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
if (dwVersion < 0x80000000)
dwBuild = (DWORD)(HIWORD(dwVersion));
std::cout << "Version: " << dwMajorVersion << "." << dwMinorVersion << " " << dwBuild << std::endl;
}
//-----------------------------------------------------------------------------
void print_os()
{
#if __APPLE__
printf("Operating System: Apple OS \n");
#elif _WIN32
printf("Operating System: Windows OS \n");
#elif __LINUX__
printf("Operating System: Linux OS \n");
#elif BSD
printf("Operating System: BSD based OS \n");
//#else
//printf("OS: Not a Windows OS");
#endif
}
//-----------------------------------------------------------------------------
void get_mem_info()
{
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx (&statex);
//percent
// _tprintf(TEXT("Currently there is: %*ld percent of memory in use."),
// WIDTH, statex.dwMemoryLoad);
std::printf("Memory (in use): %d percent",statex.dwMemoryLoad);
std::cout << " " << std::endl;
}
//-----------------------------------------------------------------------------
void check_connection()
{
int maxPingTimes = 10; // Maximum number of times you can ping
int pingTimes; // How many times to check connection
int testNum = 0; // amount of tests run
std::cout << "How many times to ping?: " << std::endl;
std::cin >> pingTimes;
// Is pingTimes equal to 1 OR less than or equal to 10?
if(pingTimes == 1 || pingTimes <= maxPingTimes)
{
std::printf("Running %d tests, please be patient...", pingTimes);
while(testNum < pingTimes)
{
while(testNum < pingTimes)
{
if( system("ping www.google.com") == 0)
{
std::cout << " " << std::endl;
std::cout << "Connection successful!" << std::endl;
std::cout << "--------------------------------------" << std::endl;
std::printf("Currently completing: %d, currently at:", pingTimes);
++testNum;
}
else
{
std::cout << "Connection unsuccessful" << std::endl;
}
std::cout << "Ping completed: " << testNum << std::endl;
}
}
}
else if(pingTimes > maxPingTimes)
{
std::cout << "pingTimes must be less than 10" << std::endl;
}
else if(pingTimes == 0)
{
std::cout << "pingTimes cannot be set to 0" << std::endl;
}
}
//-----------------------------------------------------------------------------
void get_ram()
{
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
std::cout << "Physical RAM: " << (float)statex.ullTotalPhys/(1024*1024*1024) << std::endl;
}
//-----------------------------------------------------------------------------
int main()
{
char ans;
bool check_conn_ans;
TCHAR user[UNLEN+1];
DWORD user_len = UNLEN+1;
GetUserName((TCHAR*)user, &user_len);
do {
std::cout << "Do you want to run a connection test? (y/n)" << std::endl;
std::cin >> ans;
std::cout << "\n";
if(ans == 'y' || ans == 'Y'){
std::cout << "Check connection?: " << std::boolalpha << true << std::endl;
get_username();
get_compname();
get_version();
print_os();
get_mem_info();
get_ram();
check_connection();
}
else if(ans == 'n' || ans == 'N')
{
std::cout<< "Check Connection?: " << std::boolalpha << false << std::endl;
get_username();
get_compname();
get_version();
print_os();
get_mem_info();
get_ram();
break;
}
else if(ans =='q'|| ans == 'Q' )
{
std::cout << "Exiting.." << std::endl;
break;
}
else if(isdigit(ans))
{
std::cout << ans << "Cannot be digit. (y/n OR Y/N)" << std::endl;
}
}
while(ans != 'y' || ans !='Y' || ans != 'n' || ans !='N' || ans != 'q' || ans != 'Q');
}