code-poltergeist-system-monitor 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of code-poltergeist-system-monitor might be problematic. Click here for more details.

Files changed (33) hide show
  1. package/index.js +74 -0
  2. package/package.json +21 -0
  3. package/te/node_modules/.package-lock.json +44 -0
  4. package/te/node_modules/code-poltergeist-system-monitor/index.js +74 -0
  5. package/te/node_modules/code-poltergeist-system-monitor/package.json +21 -0
  6. package/te/node_modules/systeminformation/LICENSE +20 -0
  7. package/te/node_modules/systeminformation/README.md +1116 -0
  8. package/te/node_modules/systeminformation/lib/audio.js +222 -0
  9. package/te/node_modules/systeminformation/lib/battery.js +311 -0
  10. package/te/node_modules/systeminformation/lib/bluetooth.js +231 -0
  11. package/te/node_modules/systeminformation/lib/cli.js +91 -0
  12. package/te/node_modules/systeminformation/lib/cpu.js +1834 -0
  13. package/te/node_modules/systeminformation/lib/docker.js +758 -0
  14. package/te/node_modules/systeminformation/lib/dockerSocket.js +327 -0
  15. package/te/node_modules/systeminformation/lib/filesystem.js +1510 -0
  16. package/te/node_modules/systeminformation/lib/graphics.js +1125 -0
  17. package/te/node_modules/systeminformation/lib/index.d.ts +1041 -0
  18. package/te/node_modules/systeminformation/lib/index.js +504 -0
  19. package/te/node_modules/systeminformation/lib/internet.js +237 -0
  20. package/te/node_modules/systeminformation/lib/memory.js +575 -0
  21. package/te/node_modules/systeminformation/lib/network.js +1783 -0
  22. package/te/node_modules/systeminformation/lib/osinfo.js +1179 -0
  23. package/te/node_modules/systeminformation/lib/printer.js +210 -0
  24. package/te/node_modules/systeminformation/lib/processes.js +1296 -0
  25. package/te/node_modules/systeminformation/lib/system.js +742 -0
  26. package/te/node_modules/systeminformation/lib/usb.js +279 -0
  27. package/te/node_modules/systeminformation/lib/users.js +363 -0
  28. package/te/node_modules/systeminformation/lib/util.js +1373 -0
  29. package/te/node_modules/systeminformation/lib/virtualbox.js +107 -0
  30. package/te/node_modules/systeminformation/lib/wifi.js +834 -0
  31. package/te/node_modules/systeminformation/package.json +99 -0
  32. package/te/package-lock.json +52 -0
  33. package/te/package.json +15 -0
@@ -0,0 +1,834 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // wifi.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2024
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 9. wifi
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const os = require('os');
17
+ const exec = require('child_process').exec;
18
+ const execSync = require('child_process').execSync;
19
+ const util = require('./util');
20
+
21
+ let _platform = process.platform;
22
+
23
+ const _linux = (_platform === 'linux' || _platform === 'android');
24
+ const _darwin = (_platform === 'darwin');
25
+ const _windows = (_platform === 'win32');
26
+
27
+ function wifiDBFromQuality(quality) {
28
+ const qual = parseFloat(quality);
29
+ if (qual < 0) { return 0; }
30
+ if (qual >= 100) { return -50; }
31
+ return (qual / 2 - 100);
32
+ }
33
+
34
+ function wifiQualityFromDB(db) {
35
+ const result = 2 * (parseFloat(db) + 100);
36
+ return result <= 100 ? result : 100;
37
+ }
38
+
39
+ const _wifi_frequencies = {
40
+ 1: 2412,
41
+ 2: 2417,
42
+ 3: 2422,
43
+ 4: 2427,
44
+ 5: 2432,
45
+ 6: 2437,
46
+ 7: 2442,
47
+ 8: 2447,
48
+ 9: 2452,
49
+ 10: 2457,
50
+ 11: 2462,
51
+ 12: 2467,
52
+ 13: 2472,
53
+ 14: 2484,
54
+ 32: 5160,
55
+ 34: 5170,
56
+ 36: 5180,
57
+ 38: 5190,
58
+ 40: 5200,
59
+ 42: 5210,
60
+ 44: 5220,
61
+ 46: 5230,
62
+ 48: 5240,
63
+ 50: 5250,
64
+ 52: 5260,
65
+ 54: 5270,
66
+ 56: 5280,
67
+ 58: 5290,
68
+ 60: 5300,
69
+ 62: 5310,
70
+ 64: 5320,
71
+ 68: 5340,
72
+ 96: 5480,
73
+ 100: 5500,
74
+ 102: 5510,
75
+ 104: 5520,
76
+ 106: 5530,
77
+ 108: 5540,
78
+ 110: 5550,
79
+ 112: 5560,
80
+ 114: 5570,
81
+ 116: 5580,
82
+ 118: 5590,
83
+ 120: 5600,
84
+ 122: 5610,
85
+ 124: 5620,
86
+ 126: 5630,
87
+ 128: 5640,
88
+ 132: 5660,
89
+ 134: 5670,
90
+ 136: 5680,
91
+ 138: 5690,
92
+ 140: 5700,
93
+ 142: 5710,
94
+ 144: 5720,
95
+ 149: 5745,
96
+ 151: 5755,
97
+ 153: 5765,
98
+ 155: 5775,
99
+ 157: 5785,
100
+ 159: 5795,
101
+ 161: 5805,
102
+ 165: 5825,
103
+ 169: 5845,
104
+ 173: 5865,
105
+ 183: 4915,
106
+ 184: 4920,
107
+ 185: 4925,
108
+ 187: 4935,
109
+ 188: 4940,
110
+ 189: 4945,
111
+ 192: 4960,
112
+ 196: 4980
113
+ };
114
+
115
+ function wifiFrequencyFromChannel(channel) {
116
+ return {}.hasOwnProperty.call(_wifi_frequencies, channel) ? _wifi_frequencies[channel] : null;
117
+ }
118
+
119
+ function wifiChannelFromFrequencs(frequency) {
120
+ let channel = 0;
121
+ for (let key in _wifi_frequencies) {
122
+ if ({}.hasOwnProperty.call(_wifi_frequencies, key)) {
123
+ if (_wifi_frequencies[key] === frequency) { channel = util.toInt(key); }
124
+ }
125
+ }
126
+ return channel;
127
+ }
128
+
129
+ function ifaceListLinux() {
130
+ const result = [];
131
+ const cmd = 'iw dev 2>/dev/null';
132
+ try {
133
+ const all = execSync(cmd, util.execOptsLinux).toString().split('\n').map(line => line.trim()).join('\n');
134
+ const parts = all.split('\nInterface ');
135
+ parts.shift();
136
+ parts.forEach(ifaceDetails => {
137
+ const lines = ifaceDetails.split('\n');
138
+ const iface = lines[0];
139
+ const id = util.toInt(util.getValue(lines, 'ifindex', ' '));
140
+ const mac = util.getValue(lines, 'addr', ' ');
141
+ const channel = util.toInt(util.getValue(lines, 'channel', ' '));
142
+ result.push({
143
+ id,
144
+ iface,
145
+ mac,
146
+ channel
147
+ });
148
+ });
149
+ return result;
150
+ } catch (e) {
151
+ try {
152
+ const all = execSync('nmcli -t -f general,wifi-properties,wired-properties,interface-flags,capabilities,nsp device show 2>/dev/null', util.execOptsLinux).toString();
153
+ const parts = all.split('\n\n');
154
+ let i = 1;
155
+ parts.forEach(ifaceDetails => {
156
+ const lines = ifaceDetails.split('\n');
157
+ const iface = util.getValue(lines, 'GENERAL.DEVICE');
158
+ const type = util.getValue(lines, 'GENERAL.TYPE');
159
+ const id = i++; // // util.getValue(lines, 'GENERAL.PATH');
160
+ const mac = util.getValue(lines, 'GENERAL.HWADDR');
161
+ const channel = '';
162
+ if (type.toLowerCase() === 'wifi') {
163
+ result.push({
164
+ id,
165
+ iface,
166
+ mac,
167
+ channel
168
+ });
169
+ }
170
+ });
171
+ return result;
172
+ } catch (e) {
173
+ return [];
174
+ }
175
+ }
176
+ }
177
+
178
+ function nmiDeviceLinux(iface) {
179
+ const cmd = `nmcli -t -f general,wifi-properties,capabilities,ip4,ip6 device show ${iface} 2>/dev/null`;
180
+ try {
181
+ const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
182
+ const ssid = util.getValue(lines, 'GENERAL.CONNECTION');
183
+ return {
184
+ iface,
185
+ type: util.getValue(lines, 'GENERAL.TYPE'),
186
+ vendor: util.getValue(lines, 'GENERAL.VENDOR'),
187
+ product: util.getValue(lines, 'GENERAL.PRODUCT'),
188
+ mac: util.getValue(lines, 'GENERAL.HWADDR').toLowerCase(),
189
+ ssid: ssid !== '--' ? ssid : null
190
+ };
191
+ } catch (e) {
192
+ return {};
193
+ }
194
+ }
195
+
196
+ function nmiConnectionLinux(ssid) {
197
+ const cmd = `nmcli -t --show-secrets connection show ${ssid} 2>/dev/null`;
198
+ try {
199
+ const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
200
+ const bssid = util.getValue(lines, '802-11-wireless.seen-bssids').toLowerCase();
201
+ return {
202
+ ssid: ssid !== '--' ? ssid : null,
203
+ uuid: util.getValue(lines, 'connection.uuid'),
204
+ type: util.getValue(lines, 'connection.type'),
205
+ autoconnect: util.getValue(lines, 'connection.autoconnect') === 'yes',
206
+ security: util.getValue(lines, '802-11-wireless-security.key-mgmt'),
207
+ bssid: bssid !== '--' ? bssid : null
208
+ };
209
+ } catch (e) {
210
+ return {};
211
+ }
212
+ }
213
+
214
+ function wpaConnectionLinux(iface) {
215
+ if (!iface) {
216
+ return {};
217
+ }
218
+ const cmd = `wpa_cli -i ${iface} status 2>&1`;
219
+ try {
220
+ const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
221
+ const freq = util.toInt(util.getValue(lines, 'freq', '='));
222
+ return {
223
+ ssid: util.getValue(lines, 'ssid', '='),
224
+ uuid: util.getValue(lines, 'uuid', '='),
225
+ security: util.getValue(lines, 'key_mgmt', '='),
226
+ freq,
227
+ channel: wifiChannelFromFrequencs(freq),
228
+ bssid: util.getValue(lines, 'bssid', '=').toLowerCase()
229
+ };
230
+ } catch (e) {
231
+ return {};
232
+ }
233
+ }
234
+
235
+ function getWifiNetworkListNmi() {
236
+ const result = [];
237
+ const cmd = 'nmcli -t -m multiline --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list 2>/dev/null';
238
+ try {
239
+ const stdout = execSync(cmd, util.execOptsLinux);
240
+ const parts = stdout.toString().split('ACTIVE:');
241
+ parts.shift();
242
+ parts.forEach(part => {
243
+ part = 'ACTIVE:' + part;
244
+ const lines = part.split(os.EOL);
245
+ const channel = util.getValue(lines, 'CHAN');
246
+ const frequency = util.getValue(lines, 'FREQ').toLowerCase().replace('mhz', '').trim();
247
+ const security = util.getValue(lines, 'SECURITY').replace('(', '').replace(')', '');
248
+ const wpaFlags = util.getValue(lines, 'WPA-FLAGS').replace('(', '').replace(')', '');
249
+ const rsnFlags = util.getValue(lines, 'RSN-FLAGS').replace('(', '').replace(')', '');
250
+ const quality = util.getValue(lines, 'SIGNAL');
251
+ result.push({
252
+ ssid: util.getValue(lines, 'SSID'),
253
+ bssid: util.getValue(lines, 'BSSID').toLowerCase(),
254
+ mode: util.getValue(lines, 'MODE'),
255
+ channel: channel ? parseInt(channel, 10) : null,
256
+ frequency: frequency ? parseInt(frequency, 10) : null,
257
+ signalLevel: wifiDBFromQuality(quality),
258
+ quality: quality ? parseInt(quality, 10) : null,
259
+ security: security && security !== 'none' ? security.split(' ') : [],
260
+ wpaFlags: wpaFlags && wpaFlags !== 'none' ? wpaFlags.split(' ') : [],
261
+ rsnFlags: rsnFlags && rsnFlags !== 'none' ? rsnFlags.split(' ') : []
262
+ });
263
+ });
264
+ return result;
265
+ } catch (e) {
266
+ return [];
267
+ }
268
+ }
269
+
270
+ function getWifiNetworkListIw(iface) {
271
+ const result = [];
272
+ try {
273
+ let iwlistParts = execSync(`export LC_ALL=C; iwlist ${iface} scan 2>&1; unset LC_ALL`, util.execOptsLinux).toString().split(' Cell ');
274
+ if (iwlistParts[0].indexOf('resource busy') >= 0) { return -1; }
275
+ if (iwlistParts.length > 1) {
276
+ iwlistParts.shift();
277
+ iwlistParts.forEach(element => {
278
+ const lines = element.split('\n');
279
+ const channel = util.getValue(lines, 'channel', ':', true);
280
+ const address = (lines && lines.length && lines[0].indexOf('Address:') >= 0 ? lines[0].split('Address:')[1].trim().toLowerCase() : '');
281
+ const mode = util.getValue(lines, 'mode', ':', true);
282
+ const frequency = util.getValue(lines, 'frequency', ':', true);
283
+ const qualityString = util.getValue(lines, 'Quality', '=', true);
284
+ const dbParts = qualityString.toLowerCase().split('signal level=');
285
+ const db = dbParts.length > 1 ? util.toInt(dbParts[1]) : 0;
286
+ const quality = db ? wifiQualityFromDB(db) : 0;
287
+ const ssid = util.getValue(lines, 'essid', ':', true);
288
+
289
+ // security and wpa-flags
290
+ const isWpa = element.indexOf(' WPA ') >= 0;
291
+ const isWpa2 = element.indexOf('WPA2 ') >= 0;
292
+ const security = [];
293
+ if (isWpa) { security.push('WPA'); }
294
+ if (isWpa2) { security.push('WPA2'); }
295
+ const wpaFlags = [];
296
+ let wpaFlag = '';
297
+ lines.forEach(function (line) {
298
+ const l = line.trim().toLowerCase();
299
+ if (l.indexOf('group cipher') >= 0) {
300
+ if (wpaFlag) {
301
+ wpaFlags.push(wpaFlag);
302
+ }
303
+ const parts = l.split(':');
304
+ if (parts.length > 1) {
305
+ wpaFlag = parts[1].trim().toUpperCase();
306
+ }
307
+ }
308
+ if (l.indexOf('pairwise cipher') >= 0) {
309
+ const parts = l.split(':');
310
+ if (parts.length > 1) {
311
+ if (parts[1].indexOf('tkip')) { wpaFlag = (wpaFlag ? 'TKIP/' + wpaFlag : 'TKIP'); }
312
+ else if (parts[1].indexOf('ccmp')) { wpaFlag = (wpaFlag ? 'CCMP/' + wpaFlag : 'CCMP'); }
313
+ else if (parts[1].indexOf('proprietary')) { wpaFlag = (wpaFlag ? 'PROP/' + wpaFlag : 'PROP'); }
314
+ }
315
+ }
316
+ if (l.indexOf('authentication suites') >= 0) {
317
+ const parts = l.split(':');
318
+ if (parts.length > 1) {
319
+ if (parts[1].indexOf('802.1x')) { wpaFlag = (wpaFlag ? '802.1x/' + wpaFlag : '802.1x'); }
320
+ else if (parts[1].indexOf('psk')) { wpaFlag = (wpaFlag ? 'PSK/' + wpaFlag : 'PSK'); }
321
+ }
322
+ }
323
+ });
324
+ if (wpaFlag) {
325
+ wpaFlags.push(wpaFlag);
326
+ }
327
+
328
+ result.push({
329
+ ssid,
330
+ bssid: address,
331
+ mode,
332
+ channel: channel ? util.toInt(channel) : null,
333
+ frequency: frequency ? util.toInt(frequency.replace('.', '')) : null,
334
+ signalLevel: db,
335
+ quality,
336
+ security,
337
+ wpaFlags,
338
+ rsnFlags: []
339
+ });
340
+ });
341
+ }
342
+ return result;
343
+ } catch (e) {
344
+ return -1;
345
+ }
346
+ }
347
+
348
+ function parseWifiDarwin(wifiObj) {
349
+ const result = [];
350
+ if (wifiObj) {
351
+ wifiObj.forEach(function (wifiItem) {
352
+ const signalLevel = wifiItem.RSSI;
353
+ let security = [];
354
+ let wpaFlags = [];
355
+ let ssid = wifiItem.SSID_STR || '';
356
+ if (wifiItem.WPA_IE) {
357
+ security.push('WPA');
358
+ if (wifiItem.WPA_IE.IE_KEY_WPA_UCIPHERS) {
359
+ wifiItem.WPA_IE.IE_KEY_WPA_UCIPHERS.forEach(function (ciphers) {
360
+ if (ciphers === 0 && wpaFlags.indexOf('unknown/TKIP') === -1) { wpaFlags.push('unknown/TKIP'); }
361
+ if (ciphers === 2 && wpaFlags.indexOf('PSK/TKIP') === -1) { wpaFlags.push('PSK/TKIP'); }
362
+ if (ciphers === 4 && wpaFlags.indexOf('PSK/AES') === -1) { wpaFlags.push('PSK/AES'); }
363
+ });
364
+ }
365
+ }
366
+ if (wifiItem.RSN_IE) {
367
+ security.push('WPA2');
368
+ if (wifiItem.RSN_IE.IE_KEY_RSN_UCIPHERS) {
369
+ wifiItem.RSN_IE.IE_KEY_RSN_UCIPHERS.forEach(function (ciphers) {
370
+ if (ciphers === 0 && wpaFlags.indexOf('unknown/TKIP') === -1) { wpaFlags.push('unknown/TKIP'); }
371
+ if (ciphers === 2 && wpaFlags.indexOf('TKIP/TKIP') === -1) { wpaFlags.push('TKIP/TKIP'); }
372
+ if (ciphers === 4 && wpaFlags.indexOf('PSK/AES') === -1) { wpaFlags.push('PSK/AES'); }
373
+ });
374
+ }
375
+ }
376
+ if (wifiItem.SSID && ssid === '') {
377
+ try {
378
+ ssid = Buffer.from(wifiItem.SSID, 'base64').toString('utf8');
379
+ } catch (err) {
380
+ util.noop();
381
+ }
382
+ }
383
+ result.push({
384
+ ssid,
385
+ bssid: wifiItem.BSSID || '',
386
+ mode: '',
387
+ channel: wifiItem.CHANNEL,
388
+ frequency: wifiFrequencyFromChannel(wifiItem.CHANNEL),
389
+ signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
390
+ quality: wifiQualityFromDB(signalLevel),
391
+ security,
392
+ wpaFlags,
393
+ rsnFlags: []
394
+ });
395
+ });
396
+ }
397
+ return result;
398
+ }
399
+ function wifiNetworks(callback) {
400
+ return new Promise((resolve) => {
401
+ process.nextTick(() => {
402
+ let result = [];
403
+ if (_linux) {
404
+ result = getWifiNetworkListNmi();
405
+ if (result.length === 0) {
406
+ try {
407
+ const iwconfigParts = execSync('export LC_ALL=C; iwconfig 2>/dev/null; unset LC_ALL', util.execOptsLinux).toString().split('\n\n');
408
+ let iface = '';
409
+ iwconfigParts.forEach(element => {
410
+ if (element.indexOf('no wireless') === -1 && element.trim() !== '') {
411
+ iface = element.split(' ')[0];
412
+ }
413
+ });
414
+ if (iface) {
415
+ let ifaceSanitized = '';
416
+ const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface, true);
417
+ const l = util.mathMin(s.length, 2000);
418
+
419
+ for (let i = 0; i <= l; i++) {
420
+ if (s[i] !== undefined) {
421
+ ifaceSanitized = ifaceSanitized + s[i];
422
+ }
423
+ }
424
+
425
+ const res = getWifiNetworkListIw(ifaceSanitized);
426
+ if (res === -1) {
427
+ // try again after 4 secs
428
+ setTimeout(function (iface) {
429
+ const res = getWifiNetworkListIw(iface);
430
+ if (res != -1) { result = res; }
431
+ if (callback) {
432
+ callback(result);
433
+ }
434
+ resolve(result);
435
+ }, 4000);
436
+ } else {
437
+ result = res;
438
+ if (callback) {
439
+ callback(result);
440
+ }
441
+ resolve(result);
442
+ }
443
+ } else {
444
+ if (callback) {
445
+ callback(result);
446
+ }
447
+ resolve(result);
448
+ }
449
+ } catch (e) {
450
+ if (callback) {
451
+ callback(result);
452
+ }
453
+ resolve(result);
454
+ }
455
+ } else {
456
+ if (callback) {
457
+ callback(result);
458
+ }
459
+ resolve(result);
460
+ }
461
+ } else if (_darwin) {
462
+ let cmd = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s -x';
463
+ exec(cmd, { maxBuffer: 1024 * 40000 }, function (error, stdout) {
464
+ const output = stdout.toString();
465
+ result = parseWifiDarwin(util.plistParser(output));
466
+ if (callback) {
467
+ callback(result);
468
+ }
469
+ resolve(result);
470
+ });
471
+ } else if (_windows) {
472
+ let cmd = 'netsh wlan show networks mode=Bssid';
473
+ util.powerShell(cmd).then((stdout) => {
474
+ const ssidParts = stdout.toString('utf8').split(os.EOL + os.EOL + 'SSID ');
475
+ ssidParts.shift();
476
+
477
+ ssidParts.forEach(ssidPart => {
478
+ const ssidLines = ssidPart.split(os.EOL);
479
+ if (ssidLines && ssidLines.length >= 8 && ssidLines[0].indexOf(':') >= 0) {
480
+ const bssidsParts = ssidPart.split(' BSSID');
481
+ bssidsParts.shift();
482
+
483
+ bssidsParts.forEach((bssidPart) => {
484
+ const bssidLines = bssidPart.split(os.EOL);
485
+ const bssidLine = bssidLines[0].split(':');
486
+ bssidLine.shift();
487
+ const bssid = bssidLine.join(':').trim().toLowerCase();
488
+ const channel = bssidLines[3].split(':').pop().trim();
489
+ const quality = bssidLines[1].split(':').pop().trim();
490
+
491
+ result.push({
492
+ ssid: ssidLines[0].split(':').pop().trim(),
493
+ bssid,
494
+ mode: '',
495
+ channel: channel ? parseInt(channel, 10) : null,
496
+ frequency: wifiFrequencyFromChannel(channel),
497
+ signalLevel: wifiDBFromQuality(quality),
498
+ quality: quality ? parseInt(quality, 10) : null,
499
+ security: [ssidLines[2].split(':').pop().trim()],
500
+ wpaFlags: [ssidLines[3].split(':').pop().trim()],
501
+ rsnFlags: []
502
+ });
503
+ });
504
+ }
505
+ });
506
+
507
+ if (callback) {
508
+ callback(result);
509
+ }
510
+ resolve(result);
511
+ });
512
+ } else {
513
+ if (callback) {
514
+ callback(result);
515
+ }
516
+ resolve(result);
517
+ }
518
+ });
519
+ });
520
+ }
521
+
522
+ exports.wifiNetworks = wifiNetworks;
523
+
524
+ function getVendor(model) {
525
+ model = model.toLowerCase();
526
+ let result = '';
527
+ if (model.indexOf('intel') >= 0) { result = 'Intel'; }
528
+ else if (model.indexOf('realtek') >= 0) { result = 'Realtek'; }
529
+ else if (model.indexOf('qualcom') >= 0) { result = 'Qualcom'; }
530
+ else if (model.indexOf('broadcom') >= 0) { result = 'Broadcom'; }
531
+ else if (model.indexOf('cavium') >= 0) { result = 'Cavium'; }
532
+ else if (model.indexOf('cisco') >= 0) { result = 'Cisco'; }
533
+ else if (model.indexOf('marvel') >= 0) { result = 'Marvel'; }
534
+ else if (model.indexOf('zyxel') >= 0) { result = 'Zyxel'; }
535
+ else if (model.indexOf('melanox') >= 0) { result = 'Melanox'; }
536
+ else if (model.indexOf('d-link') >= 0) { result = 'D-Link'; }
537
+ else if (model.indexOf('tp-link') >= 0) { result = 'TP-Link'; }
538
+ else if (model.indexOf('asus') >= 0) { result = 'Asus'; }
539
+ else if (model.indexOf('linksys') >= 0) { result = 'Linksys'; }
540
+ return result;
541
+ }
542
+
543
+ function formatBssid(s) {
544
+ s = s.replace(/</g, '').replace(/>/g, '').match(/.{1,2}/g) || [];
545
+ return s.join(':');
546
+ }
547
+
548
+ function wifiConnections(callback) {
549
+
550
+ return new Promise((resolve) => {
551
+ process.nextTick(() => {
552
+ const result = [];
553
+
554
+ if (_linux) {
555
+ const ifaces = ifaceListLinux();
556
+ const networkList = getWifiNetworkListNmi();
557
+ ifaces.forEach(ifaceDetail => {
558
+ let ifaceSanitized = '';
559
+ const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(ifaceDetail.iface, true);
560
+ const ll = util.mathMin(s.length, 2000);
561
+
562
+ for (let i = 0; i <= ll; i++) {
563
+ if (s[i] !== undefined) {
564
+ ifaceSanitized = ifaceSanitized + s[i];
565
+ }
566
+ }
567
+
568
+ const nmiDetails = nmiDeviceLinux(ifaceSanitized);
569
+ const wpaDetails = wpaConnectionLinux(ifaceSanitized);
570
+ const ssid = nmiDetails.ssid || wpaDetails.ssid;
571
+ const network = networkList.filter(nw => nw.ssid === ssid);
572
+ let ssidSanitized = '';
573
+ const t = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(ssid, true);
574
+ const l = util.mathMin(t.length, 2000);
575
+ for (let i = 0; i <= l; i++) {
576
+ if (t[i] !== undefined) {
577
+ ssidSanitized = ssidSanitized + t[i];
578
+ }
579
+ }
580
+
581
+ const nmiConnection = nmiConnectionLinux(ssidSanitized);
582
+ const channel = network && network.length && network[0].channel ? network[0].channel : (wpaDetails.channel ? wpaDetails.channel : null);
583
+ const bssid = network && network.length && network[0].bssid ? network[0].bssid : (wpaDetails.bssid ? wpaDetails.bssid : null);
584
+ const signalLevel = network && network.length && network[0].signalLevel ? network[0].signalLevel : null;
585
+ if (ssid && bssid) {
586
+ result.push({
587
+ id: ifaceDetail.id,
588
+ iface: ifaceDetail.iface,
589
+ model: nmiDetails.product,
590
+ ssid,
591
+ bssid: network && network.length && network[0].bssid ? network[0].bssid : (wpaDetails.bssid ? wpaDetails.bssid : null),
592
+ channel,
593
+ frequency: channel ? wifiFrequencyFromChannel(channel) : null,
594
+ type: nmiConnection.type ? nmiConnection.type : '802.11',
595
+ security: nmiConnection.security ? nmiConnection.security : (wpaDetails.security ? wpaDetails.security : null),
596
+ signalLevel,
597
+ quality: wifiQualityFromDB(signalLevel),
598
+ txRate: null
599
+ });
600
+ }
601
+ });
602
+ if (callback) {
603
+ callback(result);
604
+ }
605
+ resolve(result);
606
+ } else if (_darwin) {
607
+ let cmd = 'system_profiler SPNetworkDataType';
608
+ exec(cmd, function (error, stdout) {
609
+ const parts1 = stdout.toString().split('\n\n Wi-Fi:\n\n');
610
+ if (parts1.length > 1) {
611
+ const lines = parts1[1].split('\n\n')[0].split('\n');
612
+ const iface = util.getValue(lines, 'BSD Device Name', ':', true);
613
+ const model = util.getValue(lines, 'hardware', ':', true);
614
+ cmd = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I 2>/dev/null; echo "######" ; ioreg -n AppleBCMWLANSkywalkInterface -r 2>/dev/null';
615
+ exec(cmd, function (error, stdout) {
616
+ const parts = stdout.toString().split('######');
617
+ const lines2 = parts[0].split('\n');
618
+ let lines3 = [];
619
+ if (parts[1].indexOf(' | {') > 0 && parts[1].indexOf(' | }') > parts[1].indexOf(' | {')) {
620
+ lines3 = parts[1].split(' | {')[1].split(' | }')[0].replace(/ \| /g, '').replace(/"/g, '').split('\n');
621
+ }
622
+ if (lines2.length > 10) {
623
+ const ssid = util.getValue(lines2, 'ssid', ':', true);
624
+ const bssid = util.getValue(lines2, 'bssid', ':', true) || formatBssid(util.getValue(lines3, 'IO80211BSSID', '=', true));
625
+ const security = util.getValue(lines2, 'link auth', ':', true);
626
+ const txRate = util.getValue(lines2, 'lastTxRate', ':', true);
627
+ const channel = util.getValue(lines2, 'channel', ':', true).split(',')[0];
628
+ const type = '802.11';
629
+ const rssi = util.toInt(util.getValue(lines2, 'agrCtlRSSI', ':', true));
630
+ /// const noise = util.toInt(util.getValue(lines2, 'agrCtlNoise', ':', true));
631
+ const signalLevel = rssi;
632
+ if (ssid || bssid) {
633
+ result.push({
634
+ id: 'Wi-Fi',
635
+ iface,
636
+ model,
637
+ ssid,
638
+ bssid,
639
+ channel: util.toInt(channel),
640
+ frequency: channel ? wifiFrequencyFromChannel(channel) : null,
641
+ type,
642
+ security,
643
+ signalLevel,
644
+ quality: wifiQualityFromDB(signalLevel),
645
+ txRate
646
+ });
647
+ }
648
+ }
649
+ if (lines3.length > 10) {
650
+ const ssid = util.getValue(lines3, 'IO80211SSID', '=', true);
651
+ const bssid = formatBssid(util.getValue(lines3, 'IO80211BSSID', '=', true));
652
+ const security = '';
653
+ const txRate = -1;
654
+ const signalLevel = -1;
655
+ const quality = -1;
656
+ const channel = util.getValue(lines3, 'IO80211Channel', '=', true);
657
+ const type = '802.11';
658
+ if ((ssid || bssid) && !result.length) {
659
+ result.push({
660
+ id: 'Wi-Fi',
661
+ iface,
662
+ model,
663
+ ssid,
664
+ bssid,
665
+ channel: util.toInt(channel),
666
+ frequency: channel ? wifiFrequencyFromChannel(channel) : null,
667
+ type,
668
+ security,
669
+ signalLevel,
670
+ quality,
671
+ txRate
672
+ });
673
+ }
674
+ }
675
+ if (callback) {
676
+ callback(result);
677
+ }
678
+ resolve(result);
679
+ });
680
+ } else {
681
+ if (callback) {
682
+ callback(result);
683
+ }
684
+ resolve(result);
685
+ }
686
+ });
687
+ } else if (_windows) {
688
+ let cmd = 'netsh wlan show interfaces';
689
+ util.powerShell(cmd).then(function (stdout) {
690
+ const allLines = stdout.toString().split('\r\n');
691
+ for (let i = 0; i < allLines.length; i++) {
692
+ allLines[i] = allLines[i].trim();
693
+ }
694
+ const parts = allLines.join('\r\n').split(':\r\n\r\n');
695
+ parts.shift();
696
+ parts.forEach(part => {
697
+ const lines = part.split('\r\n');
698
+ if (lines.length >= 5) {
699
+ const iface = lines[0].indexOf(':') >= 0 ? lines[0].split(':')[1].trim() : '';
700
+ const model = lines[1].indexOf(':') >= 0 ? lines[1].split(':')[1].trim() : '';
701
+ const id = lines[2].indexOf(':') >= 0 ? lines[2].split(':')[1].trim() : '';
702
+ const ssid = util.getValue(lines, 'SSID', ':', true);
703
+ const bssid = util.getValue(lines, 'BSSID', ':', true);
704
+ const quality = util.getValue(lines, 'Signal', ':', true);
705
+ const signalLevel = wifiDBFromQuality(quality);
706
+ const type = util.getValue(lines, 'Radio type', ':', true) || util.getValue(lines, 'Type de radio', ':', true) || util.getValue(lines, 'Funktyp', ':', true) || null;
707
+ const security = util.getValue(lines, 'authentication', ':', true) || util.getValue(lines, 'Authentification', ':', true) || util.getValue(lines, 'Authentifizierung', ':', true) || null;
708
+ const channel = util.getValue(lines, 'Channel', ':', true) || util.getValue(lines, 'Canal', ':', true) || util.getValue(lines, 'Kanal', ':', true) || null;
709
+ const txRate = util.getValue(lines, 'Transmit rate (mbps)', ':', true) || util.getValue(lines, 'Transmission (mbit/s)', ':', true) || util.getValue(lines, 'Empfangsrate (MBit/s)', ':', true) || null;
710
+ if (model && id && ssid && bssid) {
711
+ result.push({
712
+ id,
713
+ iface,
714
+ model,
715
+ ssid,
716
+ bssid,
717
+ channel: util.toInt(channel),
718
+ frequency: channel ? wifiFrequencyFromChannel(channel) : null,
719
+ type,
720
+ security,
721
+ signalLevel,
722
+ quality: quality ? parseInt(quality, 10) : null,
723
+ txRate: util.toInt(txRate) || null
724
+ });
725
+ }
726
+ }
727
+ });
728
+ if (callback) {
729
+ callback(result);
730
+ }
731
+ resolve(result);
732
+ });
733
+ } else {
734
+ if (callback) {
735
+ callback(result);
736
+ }
737
+ resolve(result);
738
+ }
739
+ });
740
+ });
741
+ }
742
+
743
+ exports.wifiConnections = wifiConnections;
744
+
745
+ function wifiInterfaces(callback) {
746
+
747
+ return new Promise((resolve) => {
748
+ process.nextTick(() => {
749
+ const result = [];
750
+
751
+ if (_linux) {
752
+ const ifaces = ifaceListLinux();
753
+ ifaces.forEach(ifaceDetail => {
754
+ const nmiDetails = nmiDeviceLinux(ifaceDetail.iface);
755
+ result.push({
756
+ id: ifaceDetail.id,
757
+ iface: ifaceDetail.iface,
758
+ model: nmiDetails.product ? nmiDetails.product : null,
759
+ vendor: nmiDetails.vendor ? nmiDetails.vendor : null,
760
+ mac: ifaceDetail.mac,
761
+ });
762
+ });
763
+ if (callback) {
764
+ callback(result);
765
+ }
766
+ resolve(result);
767
+ } else if (_darwin) {
768
+ let cmd = 'system_profiler SPNetworkDataType';
769
+ exec(cmd, function (error, stdout) {
770
+ const parts1 = stdout.toString().split('\n\n Wi-Fi:\n\n');
771
+ if (parts1.length > 1) {
772
+ const lines = parts1[1].split('\n\n')[0].split('\n');
773
+ const iface = util.getValue(lines, 'BSD Device Name', ':', true);
774
+ const mac = util.getValue(lines, 'MAC Address', ':', true);
775
+ const model = util.getValue(lines, 'hardware', ':', true);
776
+ result.push({
777
+ id: 'Wi-Fi',
778
+ iface,
779
+ model,
780
+ vendor: '',
781
+ mac
782
+ });
783
+ }
784
+ if (callback) {
785
+ callback(result);
786
+ }
787
+ resolve(result);
788
+ });
789
+ } else if (_windows) {
790
+ let cmd = 'netsh wlan show interfaces';
791
+ util.powerShell(cmd).then(function (stdout) {
792
+ const allLines = stdout.toString().split('\r\n');
793
+ for (let i = 0; i < allLines.length; i++) {
794
+ allLines[i] = allLines[i].trim();
795
+ }
796
+ const parts = allLines.join('\r\n').split(':\r\n\r\n');
797
+ parts.shift();
798
+ parts.forEach(part => {
799
+ const lines = part.split('\r\n');
800
+ if (lines.length >= 5) {
801
+ const iface = lines[0].indexOf(':') >= 0 ? lines[0].split(':')[1].trim() : '';
802
+ const model = lines[1].indexOf(':') >= 0 ? lines[1].split(':')[1].trim() : '';
803
+ const id = lines[2].indexOf(':') >= 0 ? lines[2].split(':')[1].trim() : '';
804
+ const macParts = lines[3].indexOf(':') >= 0 ? lines[3].split(':') : [];
805
+ macParts.shift();
806
+ const mac = macParts.join(':').trim();
807
+ const vendor = getVendor(model);
808
+ if (iface && model && id && mac) {
809
+ result.push({
810
+ id,
811
+ iface,
812
+ model,
813
+ vendor,
814
+ mac,
815
+ });
816
+ }
817
+ }
818
+ });
819
+ if (callback) {
820
+ callback(result);
821
+ }
822
+ resolve(result);
823
+ });
824
+ } else {
825
+ if (callback) {
826
+ callback(result);
827
+ }
828
+ resolve(result);
829
+ }
830
+ });
831
+ });
832
+ }
833
+
834
+ exports.wifiInterfaces = wifiInterfaces;