-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDownloadSpeedMonitor.txt
490 lines (406 loc) · 13.5 KB
/
DownloadSpeedMonitor.txt
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
Script("Name") = "DL Speed"
Script("Author") = "The-Black-Ninja"
Script("Major") = 1
Script("Minor") = 2
Script("Revision") = 0
'// Change Log
'//
'// :: v1.0 - v1.1 ::
'// -> Added command to display download speed as a text - Thanks 7thAce
Private downSpeed, upSpeed, speedCheckData, netAdapters
Sub Event_Load()
Call CreateCmds()
Call CreateObj("Form", "DLForm")
Call CreateObj("LongTimer", "FormUpdate")
FormUpdate.Interval = 1
FormUpdate.Enabled = False
Call CreateObj("LongTimer", "AdapterUpdate")
AdapterUpdate.Interval = 15
AdapterUpdate.Enabled = False
Call CreateObj("LongTimer", "SpeedCheck")
SpeedCheck.Interval = 1
SpeedCheck.Enabled = False
Set netAdapters = CreateObject("Scripting.Dictionary")
netAdapters.CompareMode = 1
End Sub
Sub DLForm_UnLoad(cancel)
FormUpdate.Enabled = False
AdapterUpdate.Enabled = False
AddChat vbYellow, "Closing internet speed monitor UI..."
End Sub
Sub FormUpdate_Timer()
With DLForm.GetObjByName("BytesRecieved")
.Text = GetBytesRecieved
End With
With DLForm.GetObjByName("BytesSent")
.Text = GetBytesSent
End With
With DLForm.GetObjByName("DownSpeed")
.Text = FormatNumber((DLForm.GetObjByName("BytesRecieved").Text - downSpeed)*0.0009765625, 2)
End With
With DLForm.GetObjByName("UpSpeed")
.Text = FormatNumber((DLForm.GetObjByName("BytesSent").Text - upSpeed)*0.0009765625, 2)
End With
upSpeed = DLForm.GetObjByName("BytesSent").Text
downSpeed = DLForm.GetObjByName("BytesRecieved").Text
End Sub
Sub SpeedCheck_Timer()
SpeedCheck.Enabled = False
tDown = Left(speedCheckData, InStr(speedCheckData, "|")-1)
tUp = Mid(speedCheckData, InStr(speedCheckData, "|")+1)
tTemp = tUp
tUp = Left(tUp, InStr(tUp, "|")-1)
tUser = Mid(tTemp, InStr(tTemp, "|")+1)
tSource = Mid(tUser, Len(tUser), 1)
tUser = Left(tUser, Instr(tUser, "|")-1)
Select Case tSource
Case 4: AddChat 10079232, "Download speed (KB/s): " & FormatNumber((GetBytesRecieved-tDown)*0.0009765625, 2) & ", Upload speed (KB/s): " & FormatNumber((GetBytesSent-tUp)*0.0009765625, 2)
Case 3: AddQ "/w " & tUser & " Download speed (KB/s): " & FormatNumber((GetBytesRecieved-tDown)*0.0009765625, 2) & ", Upload speed (KB/s): " & FormatNumber((GetBytesSent-tUp)*0.0009765625, 2)
Case 2: AddQ "/me Download speed (KB/s): " & FormatNumber((GetBytesRecieved-tDown)*0.0009765625, 2) & ", Upload speed (KB/s): " & FormatNumber((GetBytesSent-tUp)*0.0009765625, 2)
Case 1: AddQ "Download speed (KB/s): " & FormatNumber((GetBytesRecieved-tDown)*0.0009765625, 2) & ", Upload speed (KB/s): " & FormatNumber((GetBytesSent-tUp)*0.0009765625, 2)
End Select
End Sub
Sub AdapterUpdate_Timer()
Call GetAdapterInfo()
End Sub
Sub Event_Command(Command)
Select Case LCase(Command.Name)
Case "speedui": Call speeduiCMD(Command)
Case "speedinfo":Call speedinfoCMD(Command)
End Select
End Sub
Private Sub speeduiCMD(Command)
If Command.Username <> BotVars.Username Then Exit Sub
Call HomeScreen()
downSpeed = GetBytesRecieved
upSpeed = GetBytesSent
FormUpdate.Enabled = True
AdapterUpdate.Enabled = True
Command.Respond "Launching internet speed monitor UI..."
End Sub
Private Sub speedinfoCMD(Command)
If NOT Command.HasAccess Then Exit Sub
speedCheckData = GetBytesRecieved & "|" & GetBytesSent & "|" & Command.Username & "|" & Command.Source
SpeedCheck.Enabled = True
End Sub
Private Sub HomeScreen()
Call DLForm.CreateObj("Label", "TotalSentRecieved_Label")
With DLForm.GetObjByName("TotalSentRecieved_Label")
.Top = 100
.Left = 400
.Height = 300
.Width = 3000
.FontSize = 10
.FontUnderline = True
.Caption = "Bytes Sent / Recieved per second"
.Visible = True
End With
Call DLForm.CreateObj("Label", "BytesRecieved_Label")
With DLForm.GetObjByName("BytesRecieved_Label")
.Top = 400
.Left = 400
.Height = 200
.Width = 3000
.FontSize = 8
.FontUnderline = False
.Caption = "Total Bytes Recieved / second:"
.Visible = True
End With
Call DLForm.CreateObj("TextBox", "BytesRecieved")
With DLForm.GetObjByName("BytesRecieved")
.Top = 650
.Left = 400
.Height = 300
.Width = 2000
.BackColor = 16759296
.Text = 0
.Visible = True
End With
Call DLForm.CreateObj("Label", "BytesSent_Label")
With DLForm.GetObjByName("BytesSent_Label")
.Top = 1000
.Left = 400
.Height = 200
.FontSize = 8
.FontUnderline = False
.Width = 3000
.Caption = "Total Bytes Sent / second:"
.Visible = True
End With
Call DLForm.CreateObj("TextBox", "BytesSent")
With DLForm.GetObjByName("BytesSent")
.Top = 1250
.Left = 400
.Height = 300
.Width = 2000
.BackColor = 16759296
.Text = 0
.Visible = True
End With
Call DLForm.CreateObj("Label", "UpDownSpeed_Label")
With DLForm.GetObjByName("UpDownSpeed_Label")
.Top = 100
.Left = 3500
.Height = 300
.Width = 3500
.FontSize = 10
.FontUnderline = True
.Caption = "Upload / Download speed per second"
.Visible = True
End With
Call DLForm.CreateObj("Label", "DownSpeed_Label")
With DLForm.GetObjByName("DownSpeed_Label")
.Top = 400
.Left = 3500
.Height = 200
.Width = 3000
.FontSize = 8
.FontUnderline = False
.Caption = "Download speed (KB/s):"
.Visible = True
End With
Call DLForm.CreateObj("TextBox", "DownSpeed")
With DLForm.GetObjByName("DownSpeed")
.Top = 650
.Left = 3500
.Height = 300
.Width = 2000
.BackColor = 16759296
.Text = downSpeed
.Visible = True
End With
Call DLForm.CreateObj("Label", "UpSpeed_Label")
With DLForm.GetObjByName("UpSpeed_Label")
.Top = 1000
.Left = 3500
.Height = 200
.FontSize = 8
.FontUnderline = False
.Width = 3000
.Caption = "Upload speed (KB/s):"
.Visible = True
End With
Call DLForm.CreateObj("TextBox", "UpSpeed")
With DLForm.GetObjByName("UpSpeed")
.Top = 1250
.Left = 3500
.Height = 300
.Width = 2000
.BackColor = 16759296
.Text = upSpeed
.Visible = True
End With
Call DLForm.CreateObj("Label", "Network_Label")
With DLForm.GetObjByName("Network_Label")
.Top = 2000
.Left = 400
.Height = 300
.FontSize = 10
.FontUnderline = True
.Width = 3000
.Caption = "Network Adapter Information"
.Visible = True
End With
Call DLForm.CreateObj("Label", "AdapterList_Label")
With DLForm.GetObjByName("AdapterList_Label")
.Top = 2400
.Left = 400
.Height = 300
.FontSize = 8
.FontUnderline = False
.Width = 3000
.Caption = "Adapter List:"
.Visible = True
End With
Call DLForm.CreateObj("Label", "CurrentConnected_Label")
With DLForm.GetObjByName("CurrentConnected_Label")
.Top = 3650
.Left = 400
.Height = 300
.FontSize = 8
.FontUnderline = False
.Width = 3000
.Caption = "Current connected networks:"
.Visible = True
End With
Call DLForm.CreateObj("Label", "CurrentDisonnected_Label")
With DLForm.GetObjByName("CurrentDisonnected_Label")
.Top = 4850
.Left = 400
.Height = 300
.FontSize = 8
.FontUnderline = False
.Width = 3000
.Caption = "Current disconnected networks:"
.Visible = True
End With
Call DLForm.CreateObj("ListBox", "AdapterList")
With DLForm.GetObjByName("AdapterList")
.Top = 2650
.Width = 7000
.Height = 1000
.Left = 400
.Clear
.BackColor = 16759296
.Visible = True
End With
Call DLForm.CreateObj("ListBox", "CurrentConnectedList")
With DLForm.GetObjByName("CurrentConnectedList")
.Top = 3900
.Width = 7000
.Height = 1000
.Left = 400
.Clear
.BackColor = 10682112
.Visible = True
End With
Call DLForm.CreateObj("ListBox", "CurrentDisconnectedList")
With DLForm.GetObjByName("CurrentDisconnectedList")
.Top = 5100
.Width = 7000
.Height = 1000
.Left = 400
.Clear
.BackColor = 5731327
.Visible = True
End With
Call GetAdapterInfo()
With DLForm
.Height = 7000
.Width = 8000
.Caption = "Internet Speed Monitor by The-Black-Ninja"
.Show
End With
End Sub
Private Sub GetAdapterInfo()
GetConnectionState
nName = netAdapters.Keys
nItem = netAdapters.Items
With DLForm.GetObjByName("AdapterList")
.Clear
For Each Item In nName
.AddItem Item
Next
End With
With DLForm.GetObjByName("CurrentConnectedList")
.Clear
For i=0 To UBound(nName)
If nItem(i)(2) = "green" Then
.AddItem nItem(i)(0) & " [" & nName(i) & "] - " & nItem(i)(1)
End If
Next
End With
Call DLForm.CreateObj("ListBox", "CurrentDisconnectedList")
With DLForm.GetObjByName("CurrentDisconnectedList")
.Clear
For i=0 To UBound(nName)
If nItem(i)(2) <> "green" Then
.AddItem nItem(i)(0) & " [" & nName(i) & "] - " & nItem(i)(1)
End If
Next
End With
End Sub
Private Sub CreateCmds()
Set cmd = OpenCommand("speedui")
If cmd Is Nothing Then
Set cmd = CreateCommand("speedui")
With cmd
.Description = "Displays the speed monitor UI that shows realtime upload and download speeds (bot console only)"
.RequiredRank = -1
.Save
End With
End If
Set cmd = OpenCommand("speedinfo")
If cmd Is Nothing Then
Set cmd = CreateCommand("speedinfo")
With cmd
.Description = "Displays the current download and upload speed as text (not real time)"
.RequiredRank = 200
.Save
End With
End If
Set cmd = Nothing
End Sub
Private Function GetBytesRecieved
Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set perfRaw = WMIService.ExecQuery("SELECT BytesReceivedPersec FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", &H10 + &H20)
For Each Item in perfRaw
GetBytesRecieved = item.BytesReceivedPersec
Exit For
Next
Set WMIService = Nothing
Set perfRaw = Nothing
End Function
Private Function GetBytesSent
Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set perfRaw = WMIService.ExecQuery("SELECT BytesSentPersec FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", &H10 + &H20)
For Each Item in perfRaw
GetBytesSent = item.BytesSentPersec
Exit For
Next
Set WMIService = Nothing
Set perfRaw = Nothing
End Function
Private Function GetConnectionState
netAdapters.RemoveAll
Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set perfRaw = WMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each item In WMIService.InstancesOf("Win32_NetworkAdapter")
If LenB(item.NetConnectionStatus) > 0 Then
Select Case item.NetConnectionStatus
Case 0
status = "Disconnected"
colour = "red"
Case 1
status = "Connecting"
colour = "yellow"
Case 2
status = "Connected"
colour = "green"
Case 3
status = "Disconnecting"
colour = "yellow"
Case 4
status = "Hardware not present"
colour = "red"
Case 5
status = "Hardware disabled"
colour = "red"
Case 6
status = "Hardware malfunction"
colour = "red"
Case 7
status = "Network cable unplugged"
colour = "red"
Case 8
status = "Authenticating"
colour = "yellow"
Case 9
status = "Authentication succeeded"
colour = "yellow"
Case 10
status = "Authentication failed"
colour = "red"
Case 11
status = "Invalid address"
colour = "red"
Case 12
status = "Credentials Required"
colour = "red"
End Select
If netAdapters.Exists(item.Name) Then item.Name = item.Name & " #2"
netAdapters.Item(item.Name) = Array(item.netconnectionid, status, colour, item.Manufacturer, item.ServiceName, item.Caption)
End If
Next
REM For Each item In perfRaw
REM If NOT IsNull(item.IPAddress) Then
REM For i = LBound(item.IPAddress) To UBound(item.IPAddress)
REM If LenB(item.IPAddress(i)) = 0 OR item.IPAddress(i) = "0.0.0.0" Then
REM "Description: " & item.Description & vbcrlf & "IP address: " & item.IPAddress(i) & " : " & item.Caption(i)
REM End if
REM Next
REM End If
REM Next
Set WMIService = Nothing
Set perfRaw = Nothing
End Function