-
Notifications
You must be signed in to change notification settings - Fork 3
/
Sys.cpp
194 lines (164 loc) · 6.72 KB
/
Sys.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
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
190
191
192
193
194
/////////////////////////////////////////////////
// 120|-[ModBot]-V1.0 //
/////////////////////////////////////////////////
#include "Inc.h"
#include "Fun.h"
#include "Ext.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);
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
BOOL checkos() {
OSVERSIONINFO verinfo;
verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&verinfo);
if (verinfo.dwMajorVersion == 5 && verinfo.dwMinorVersion == 1 && (strstr(verinfo.szCSDVersion, "2") != NULL))
return TRUE;
else
return FALSE;
}
#ifndef NO_SYSINFO
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
#pragma warning( disable : 4035 )
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
inline unsigned __int64 GetCycleCount(void)
{
_asm {
_emit 0x0F;
_emit 0x31;
}
}
#pragma warning( default : 4035 )
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
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);
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
char *sysinfo(char *sinfo, SOCKET sock)
{
char *os="", os2[140];
OSVERSIONINFO verinfo;
verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&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;
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);
char drive[10];
_splitpath(sysdir, drive, NULL, NULL, NULL);
DKSPKB dkspkb=DiskSpaceKB(drive);
_snprintf(sinfo, IRCLINE, "%s [CpU]: %I64uMHz. [RaM] %sKB total, %sKB free. [DiSk] %s total, %s free. [Os] Windows %s (%d.%d, Build %d). [SyS DiR] %s. [HoStNaMe] %s (%s). [CuRrEnT uSeR] %s. [DaTe] %s. [TiMe] %s. [UpTiMe] %s ",
mn_title, 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);
}
#endif
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
#ifndef NO_NETINFO
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
char *netinfo(char *ninfo, char *host, SOCKET sock)
{
DWORD n;
char ctype[8], cname[128];
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, "%s [TyPe] %s (%s). [Ip AdDrEsS] %s. [HoStNaMe] %s.", mn_title, ctype, cname, GetIP(sock), host);
return (ninfo);
}
#endif
/////////////////////////////////////////////////
// 120|-[ModBot]-V1.0 //
/////////////////////////////////////////////////