systeminformation 5.9.13 → 5.9.17

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.
package/lib/osinfo.js CHANGED
@@ -595,7 +595,7 @@ function versions(apps, callback) {
595
595
  }
596
596
  if ({}.hasOwnProperty.call(appsObj.versions, 'git')) {
597
597
  if (_darwin) {
598
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/git');
598
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/git') || fs.existsSync('/opt/homebrew/bin/git');
599
599
  if (util.darwinXcodeExists() || gitHomebrewExists) {
600
600
  exec('git --version', function (error, stdout) {
601
601
  if (!error) {
@@ -780,9 +780,14 @@ function versions(apps, callback) {
780
780
  }
781
781
  if ({}.hasOwnProperty.call(appsObj.versions, 'python')) {
782
782
  if (_darwin) {
783
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python');
784
- if (util.darwinXcodeExists() || gitHomebrewExists) {
785
- exec('python -V 2>&1', function (error, stdout) {
783
+ const stdout = execSync('sw_vers');
784
+ const lines = stdout.toString().split('\n');
785
+ const osVersion = util.getValue(lines, 'ProductVersion', ':');
786
+ const gitHomebrewExists1 = fs.existsSync('/usr/local/Cellar/python');
787
+ const gitHomebrewExists2 = fs.existsSync('/opt/homebrew/bin/python');
788
+ if ((util.darwinXcodeExists() && util.semverCompare('12.0.1', osVersion) < 0) || gitHomebrewExists1 || gitHomebrewExists2) {
789
+ const cmd = gitHomebrewExists1 ? '/usr/local/Cellar/python -V 2>&1' : (gitHomebrewExists2 ? '/opt/homebrew/bin/python -V 2>&1' : 'python -V 2>&1');
790
+ exec(cmd, function (error, stdout) {
786
791
  if (!error) {
787
792
  const python = stdout.toString().split('\n')[0] || '';
788
793
  appsObj.versions.python = python.toLowerCase().replace('python', '').trim();
@@ -804,7 +809,7 @@ function versions(apps, callback) {
804
809
  }
805
810
  if ({}.hasOwnProperty.call(appsObj.versions, 'python3')) {
806
811
  if (_darwin) {
807
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python3');
812
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/python3') || fs.existsSync('/opt/homebrew/bin/python3');
808
813
  if (util.darwinXcodeExists() || gitHomebrewExists) {
809
814
  exec('python3 -V 2>&1', function (error, stdout) {
810
815
  if (!error) {
@@ -828,7 +833,7 @@ function versions(apps, callback) {
828
833
  }
829
834
  if ({}.hasOwnProperty.call(appsObj.versions, 'pip')) {
830
835
  if (_darwin) {
831
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip');
836
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip') || fs.existsSync('/opt/homebrew/bin/pip');
832
837
  if (util.darwinXcodeExists() || gitHomebrewExists) {
833
838
  exec('pip -V 2>&1', function (error, stdout) {
834
839
  if (!error) {
@@ -854,7 +859,7 @@ function versions(apps, callback) {
854
859
  }
855
860
  if ({}.hasOwnProperty.call(appsObj.versions, 'pip3')) {
856
861
  if (_darwin) {
857
- const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip3');
862
+ const gitHomebrewExists = fs.existsSync('/usr/local/Cellar/pip3') || fs.existsSync('/opt/homebrew/bin/pip3');
858
863
  if (util.darwinXcodeExists() || gitHomebrewExists) {
859
864
  exec('pip3 -V 2>&1', function (error, stdout) {
860
865
  if (!error) {
package/lib/util.js CHANGED
@@ -37,6 +37,17 @@ let _smartMonToolsInstalled = null;
37
37
 
38
38
  const WINDIR = process.env.WINDIR || 'C:\\Windows';
39
39
 
40
+ // powerShell
41
+ let _psChild;
42
+ let _psResult = '';
43
+ let _psCmds = [];
44
+ let _psPersistent = false;
45
+ const _psToUTF8 = '$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8 ; ';
46
+ const _psCmdStart = '--###START###--';
47
+ const _psError = '--ERROR--';
48
+ const _psCmdSeperator = '--###ENDCMD###--';
49
+ const _psIdSeperator = '--##ID##--';
50
+
40
51
  const execOptsWin = {
41
52
  windowsHide: true,
42
53
  maxBuffer: 1024 * 20000,
@@ -352,59 +363,157 @@ function getVboxmanage() {
352
363
  return _windows ? `"${process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH}\\VBoxManage.exe"` : 'vboxmanage';
353
364
  }
354
365
 
355
- function powerShell(cmd) {
366
+ function powerShellProceedResults(data) {
367
+ let id = '';
368
+ let parts;
369
+ let res = '';
370
+ // startID
371
+ if (data.indexOf(_psCmdStart) >= 0) {
372
+ parts = data.split(_psCmdStart);
373
+ const parts2 = parts[1].split(_psIdSeperator);
374
+ id = parts2[0];
375
+ if (parts2.length > 1) {
376
+ data = parts2.slice(1).join(_psIdSeperator);
377
+ }
378
+ }
379
+ // result;
380
+ if (data.indexOf(_psCmdSeperator) >= 0) {
381
+ parts = data.split(_psCmdSeperator);
382
+ res = parts[0];
383
+ }
384
+ let remove = -1;
385
+ for (let i = 0; i < _psCmds.length; i++) {
386
+ if (_psCmds[i].id === id) {
387
+ remove = i;
388
+ // console.log(`----- TIME : ${(new Date() - _psCmds[i].start) * 0.001} s`);
356
389
 
357
- let result = '';
358
- const toUTF8 = '$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8 ; ';
390
+ _psCmds[i].callback(res);
391
+ }
392
+ }
393
+ if (remove >= 0) {
394
+ _psCmds.splice(remove, 1);
395
+ }
396
+ }
359
397
 
360
- return new Promise((resolve) => {
361
- process.nextTick(() => {
362
- try {
363
- const child = spawn('powershell.exe', ['-NoLogo', '-NoProfile', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], { // added NoProfile
364
- stdio: 'pipe',
365
- windowsHide: true,
366
- maxBuffer: 1024 * 20000,
367
- encoding: 'UTF-8',
368
- env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
369
- });
398
+ function powerShellStart() {
399
+ _psChild = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], {
400
+ stdio: 'pipe',
401
+ windowsHide: true,
402
+ maxBuffer: 1024 * 20000,
403
+ encoding: 'UTF-8',
404
+ env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
405
+ });
406
+ if (_psChild && _psChild.pid) {
407
+ _psPersistent = true;
408
+ _psChild.stdout.on('data', function (data) {
409
+ _psResult = _psResult + data.toString('utf8');
410
+ if (data.indexOf(_psCmdSeperator) >= 0) {
411
+ powerShellProceedResults(_psResult);
412
+ _psResult = '';
413
+ }
414
+ });
415
+ _psChild.stderr.on('data', function () {
416
+ powerShellProceedResults(_psResult + _psError);
417
+ });
418
+ _psChild.on('error', function () {
419
+ powerShellProceedResults(_psResult + _psError);
420
+ });
421
+ _psChild.on('close', function () {
422
+ _psChild.kill();
423
+ });
424
+ }
425
+ }
370
426
 
371
- if (child && !child.pid) {
372
- child.on('error', function () {
373
- resolve(result);
374
- });
427
+ function powerShellRelease() {
428
+ try {
429
+ _psChild.stdin.write('exit' + os.EOL);
430
+ _psChild.stdin.end();
431
+ _psPersistent = false;
432
+ } catch (e) {
433
+ _psChild.kill();
434
+ }
435
+ }
436
+
437
+ function powerShell(cmd) {
438
+
439
+ if (_psPersistent) {
440
+ const id = Math.random().toString(36).substr(2, 10);
441
+ return new Promise((resolve) => {
442
+ process.nextTick(() => {
443
+ function callback(data) {
444
+ resolve(data);
375
445
  }
376
- if (child && child.pid) {
377
- child.stdout.on('data', function (data) {
378
- result = result + data.toString('utf8');
379
- });
380
- child.stderr.on('data', function () {
381
- child.kill();
382
- resolve(result);
383
- });
384
- child.on('close', function () {
385
- child.kill();
386
- resolve(result);
387
- });
388
- child.on('error', function () {
389
- child.kill();
390
- resolve(result);
446
+ _psCmds.push({
447
+ id,
448
+ cmd,
449
+ callback,
450
+ start: new Date()
451
+ });
452
+ try {
453
+ if (_psChild && _psChild.pid) {
454
+ _psChild.stdin.write(_psToUTF8 + 'echo ' + _psCmdStart + id + _psIdSeperator + '; ' + os.EOL + cmd + os.EOL + 'echo ' + _psCmdSeperator + os.EOL);
455
+ }
456
+ } catch (e) {
457
+ resolve('');
458
+ }
459
+ });
460
+ });
461
+
462
+ } else {
463
+ let result = '';
464
+
465
+ return new Promise((resolve) => {
466
+ process.nextTick(() => {
467
+ try {
468
+ // const start = new Date();
469
+ const child = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], {
470
+ stdio: 'pipe',
471
+ windowsHide: true,
472
+ maxBuffer: 1024 * 20000,
473
+ encoding: 'UTF-8',
474
+ env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
391
475
  });
392
- try {
393
- child.stdin.write(toUTF8 + cmd + os.EOL);
394
- child.stdin.write('exit' + os.EOL);
395
- child.stdin.end();
396
- } catch (e) {
397
- child.kill();
476
+
477
+ if (child && !child.pid) {
478
+ child.on('error', function () {
479
+ resolve(result);
480
+ });
481
+ }
482
+ if (child && child.pid) {
483
+ child.stdout.on('data', function (data) {
484
+ result = result + data.toString('utf8');
485
+ });
486
+ child.stderr.on('data', function () {
487
+ child.kill();
488
+ resolve(result);
489
+ });
490
+ child.on('close', function () {
491
+ child.kill();
492
+ // console.log(`----- TIME : ${(new Date() - start) * 0.001} s`);
493
+
494
+ resolve(result);
495
+ });
496
+ child.on('error', function () {
497
+ child.kill();
498
+ resolve(result);
499
+ });
500
+ try {
501
+ child.stdin.write(_psToUTF8 + cmd + os.EOL);
502
+ child.stdin.write('exit' + os.EOL);
503
+ child.stdin.end();
504
+ } catch (e) {
505
+ child.kill();
506
+ resolve(result);
507
+ }
508
+ } else {
398
509
  resolve(result);
399
510
  }
400
- } else {
511
+ } catch (e) {
401
512
  resolve(result);
402
513
  }
403
- } catch (e) {
404
- resolve(result);
405
- }
514
+ });
406
515
  });
407
- });
516
+ }
408
517
  }
409
518
 
410
519
  function execSafe(cmd, args, options) {
@@ -1002,91 +1111,119 @@ function linuxVersion() {
1002
1111
  }
1003
1112
 
1004
1113
  function plistParser(xmlStr) {
1005
- const tags = ['array', 'dict', 'key', 'string', 'integer', 'date', 'real', 'data'];
1006
-
1007
- function getNextTagPos() {
1008
- let result = {
1009
- pos: 999999,
1010
- tag: ''
1011
- };
1012
- tags.forEach((tag) => {
1013
- const ii = xmlStr.indexOf(`<${tag}>`);
1014
- if (ii !== -1 && ii < result.pos) {
1015
- result = {
1016
- pos: ii,
1017
- tag
1018
- };
1019
- }
1020
- });
1021
- return result;
1022
- }
1114
+ const tags = ['array', 'dict', 'key', 'string', 'integer', 'date', 'real', 'data', 'boolean', 'arrayEmpty'];
1115
+ const startStr = '<plist version';
1023
1116
 
1024
- function getNextClosingTagPos(tag) {
1025
- return xmlStr.indexOf(`</${tag}>`);
1117
+ let pos = xmlStr.indexOf(startStr);
1118
+ let len = xmlStr.length;
1119
+ while (xmlStr[pos] !== '>' && pos < len) {
1120
+ pos++;
1026
1121
  }
1027
1122
 
1028
- function parseXmlTree(isArray, closingTag) {
1029
- // start parsing
1030
- let obj = {};
1031
- let arr = [];
1032
- let cpos = getNextTagPos();
1033
- let key = '';
1034
- let valueStr = null;
1035
-
1036
- while (cpos.pos >= 0 && cpos.tag) {
1037
- let nextTagPos = getNextTagPos();
1038
- // let nextClosePos = getNextClosingTagPos(cpos.tag);
1039
- let nextClosePosBlock = closingTag ? getNextClosingTagPos(closingTag) : 999999;
1040
- if (nextClosePosBlock <= nextTagPos.pos) {
1041
- return (isArray ? arr : obj);
1123
+ let depth = 0;
1124
+ let inTagStart = false;
1125
+ let inTagContent = false;
1126
+ let inTagEnd = false;
1127
+ let metaData = [{ tagStart: '', tagEnd: '', tagContent: '', key: '', data: null }];
1128
+ let c = '';
1129
+ let cn = xmlStr[pos];
1130
+
1131
+ while (pos < len) {
1132
+ c = cn;
1133
+ if (pos + 1 < len) { cn = xmlStr[pos + 1]; }
1134
+ if (c === '<') {
1135
+ inTagContent = false;
1136
+ if (cn === '/') { inTagEnd = true; }
1137
+ else if (metaData[depth].tagStart) {
1138
+ metaData[depth].tagContent = '';
1139
+ if (!metaData[depth].data) { metaData[depth].data = metaData[depth].tagStart === 'array' ? [] : {}; }
1140
+ depth++;
1141
+ metaData.push({ tagStart: '', tagEnd: '', tagContent: '', key: null, data: null });
1142
+ inTagStart = true;
1143
+ inTagContent = false;
1042
1144
  }
1043
- xmlStr = xmlStr.substring((cpos.pos + cpos.tag.length + 2));
1044
- if (cpos.tag === 'array') {
1045
- const res = parseXmlTree(true, cpos.tag);
1046
- if (key) {
1047
- obj[key] = res;
1048
- } else {
1049
- obj = res;
1145
+ else if (!inTagStart) { inTagStart = true; }
1146
+ } else if (c === '>') {
1147
+ if (metaData[depth].tagStart === 'true/') { inTagStart = false; inTagEnd = true; metaData[depth].tagStart = ''; metaData[depth].tagEnd = '/boolean'; metaData[depth].data = true; }
1148
+ if (metaData[depth].tagStart === 'false/') { inTagStart = false; inTagEnd = true; metaData[depth].tagStart = ''; metaData[depth].tagEnd = '/boolean'; metaData[depth].data = false; }
1149
+ if (metaData[depth].tagStart === 'array/') { inTagStart = false; inTagEnd = true; metaData[depth].tagStart = ''; metaData[depth].tagEnd = '/arrayEmpty'; metaData[depth].data = []; }
1150
+ if (inTagContent) { inTagContent = false; }
1151
+ if (inTagStart) {
1152
+ inTagStart = false;
1153
+ inTagContent = true;
1154
+ if (metaData[depth].tagStart === 'array') {
1155
+ metaData[depth].data = [];
1050
1156
  }
1051
- } else if (cpos.tag === 'dict') {
1052
- const res = parseXmlTree(false, cpos.tag);
1053
- if (!isArray) {
1054
- obj[key] = res;
1055
- } else {
1056
- arr.push(res);
1157
+ if (metaData[depth].tagStart === 'dict') {
1158
+ metaData[depth].data = {};
1057
1159
  }
1058
- xmlStr = xmlStr.substring((cpos.pos + cpos.tag.length + 3));
1059
- } else {
1060
- let nextTagPos = getNextTagPos();
1061
- let nextClosePos = getNextClosingTagPos(cpos.tag);
1062
- // nextClosePosBlock = closingTag ? getNextClosingTagPos(closingTag) : 999999;
1063
- if (nextClosePos < nextTagPos.pos) {
1064
- if (cpos.tag === 'key') {
1065
- key = xmlStr.substring(0, nextClosePos);
1066
- xmlStr = xmlStr.substring(key.length + cpos.tag.length + 3); // key done
1067
- } else {
1068
- valueStr = xmlStr.substring(0, nextClosePos).replace(/\t/g, '');
1069
- if (cpos.tag === 'string') { if (!isArray) { obj[key] = valueStr; } else { arr.push(valueStr); } }
1070
- if (cpos.tag === 'integer') { if (!isArray) { obj[key] = parseInt(valueStr); } else { arr.push(parseInt(valueStr)); } }
1071
- if (cpos.tag === 'date') { if (!isArray) { obj[key] = valueStr; } else { arr.push(valueStr); } }
1072
- if (cpos.tag === 'data') { if (!isArray) { obj[key] = valueStr; } else { arr.push(valueStr); } }
1073
- if (cpos.tag === 'real') { if (!isArray) { obj[key] = parseFloat(valueStr); } else { arr.push(parseFloat(valueStr)); } }
1074
-
1075
- key = '';
1076
- xmlStr = xmlStr.substring(valueStr.length + cpos.tag.length + 3); // property done
1160
+ }
1161
+ if (inTagEnd) {
1162
+ inTagEnd = false;
1163
+ if (metaData[depth].tagEnd && tags.indexOf(metaData[depth].tagEnd.substr(1)) >= 0) {
1164
+ if (metaData[depth].tagEnd === '/dict' || metaData[depth].tagEnd === '/array') {
1165
+ if (depth > 1 && metaData[depth - 2].tagStart === 'array') {
1166
+ metaData[depth - 2].data.push(metaData[depth - 1].data);
1167
+ }
1168
+ if (depth > 1 && metaData[depth - 2].tagStart === 'dict') {
1169
+ metaData[depth - 2].data[metaData[depth - 1].key] = metaData[depth - 1].data;
1170
+ }
1171
+ depth--;
1172
+ metaData.pop();
1173
+ metaData[depth].tagContent = '';
1174
+ metaData[depth].tagStart = '';
1175
+ metaData[depth].tagEnd = '';
1176
+ }
1177
+ else {
1178
+ if (metaData[depth].tagEnd === '/key' && metaData[depth].tagContent) {
1179
+ metaData[depth].key = metaData[depth].tagContent;
1180
+ } else {
1181
+ if (metaData[depth].tagEnd === '/real' && metaData[depth].tagContent) { metaData[depth].data = parseFloat(metaData[depth].tagContent) || 0; }
1182
+ if (metaData[depth].tagEnd === '/integer' && metaData[depth].tagContent) { metaData[depth].data = parseInt(metaData[depth].tagContent) || 0; }
1183
+ if (metaData[depth].tagEnd === '/string' && metaData[depth].tagContent) { metaData[depth].data = metaData[depth].tagContent || ''; }
1184
+ if (metaData[depth].tagEnd === '/boolean') { metaData[depth].data = metaData[depth].tagContent || false; }
1185
+ if (metaData[depth].tagEnd === '/arrayEmpty') { metaData[depth].data = metaData[depth].tagContent || []; }
1186
+ if (depth > 0 && metaData[depth - 1].tagStart === 'array') { metaData[depth - 1].data.push(metaData[depth].data); }
1187
+ if (depth > 0 && metaData[depth - 1].tagStart === 'dict') { metaData[depth - 1].data[metaData[depth].key] = metaData[depth].data; }
1188
+ }
1189
+ metaData[depth].tagContent = '';
1190
+ metaData[depth].tagStart = '';
1191
+ metaData[depth].tagEnd = '';
1077
1192
  }
1078
1193
  }
1194
+ metaData[depth].tagEnd = '';
1195
+ inTagStart = false;
1196
+ inTagContent = false;
1079
1197
  }
1080
- cpos = getNextTagPos();
1198
+ } else {
1199
+ if (inTagStart) { metaData[depth].tagStart += c; }
1200
+ if (inTagEnd) { metaData[depth].tagEnd += c; }
1201
+ if (inTagContent) { metaData[depth].tagContent += c; }
1081
1202
  }
1082
- return (isArray ? arr : obj);
1203
+ pos++;
1083
1204
  }
1084
- try {
1085
- const result = parseXmlTree(false, '');
1086
- return result;
1087
- } catch (e) {
1088
- return {};
1205
+ return metaData[0].data;
1206
+ }
1207
+
1208
+ function semverCompare(v1, v2) {
1209
+ let res = 0;
1210
+ const parts1 = v1.split('.');
1211
+ const parts2 = v2.split('.');
1212
+ if (parts1[0] < parts2[0]) { res = 1; }
1213
+ else if (parts1[0] > parts2[0]) { res = -1; }
1214
+ else if (parts1[0] === parts2[0] && parts1.length >= 2 && parts2.length >= 2) {
1215
+ if (parts1[1] < parts2[1]) { res = 1; }
1216
+ else if (parts1[1] > parts2[1]) { res = -1; }
1217
+ else if (parts1[1] === parts2[1]) {
1218
+ if (parts1.length >= 3 && parts2.length >= 3) {
1219
+ if (parts1[2] < parts2[2]) { res = 1; }
1220
+ else if (parts1[2] > parts2[2]) { res = -1; }
1221
+ } else if (parts2.length >= 3) {
1222
+ res = 1;
1223
+ }
1224
+ }
1089
1225
  }
1226
+ return res;
1090
1227
  }
1091
1228
 
1092
1229
  function noop() { }
@@ -1109,6 +1246,8 @@ exports.wmic = wmic;
1109
1246
  exports.darwinXcodeExists = darwinXcodeExists;
1110
1247
  exports.getVboxmanage = getVboxmanage;
1111
1248
  exports.powerShell = powerShell;
1249
+ exports.powerShellStart = powerShellStart;
1250
+ exports.powerShellRelease = powerShellRelease;
1112
1251
  exports.execSafe = execSafe;
1113
1252
  exports.nanoSeconds = nanoSeconds;
1114
1253
  exports.countUniqueLines = countUniqueLines;
@@ -1134,3 +1273,4 @@ exports.stringStartWith = stringStartWith;
1134
1273
  exports.mathMin = mathMin;
1135
1274
  exports.WINDIR = WINDIR;
1136
1275
  exports.getFilesInPath = getFilesInPath;
1276
+ exports.semverCompare = semverCompare;
package/lib/wifi.js CHANGED
@@ -315,8 +315,77 @@ function getWifiNetworkListIw(iface) {
315
315
  }
316
316
  }
317
317
 
318
- function wifiNetworks(callback) {
318
+ /*
319
+ ssid: line.substring(parsedhead[0].from, parsedhead[0].to).trim(),
320
+ bssid: line.substring(parsedhead[1].from, parsedhead[1].to).trim().toLowerCase(),
321
+ mode: '',
322
+ channel,
323
+ frequency: wifiFrequencyFromChannel(channel),
324
+ signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
325
+ quality: wifiQualityFromDB(signalLevel),
326
+ security,
327
+ wpaFlags,
328
+ rsnFlags: []
329
+
330
+ const securityAll = line.substring(parsedhead[6].from, 1000).trim().split(' ');
331
+ let security = [];
332
+ let wpaFlags = [];
333
+ securityAll.forEach(securitySingle => {
334
+ if (securitySingle.indexOf('(') > 0) {
335
+ const parts = securitySingle.split('(');
336
+ security.push(parts[0]);
337
+ wpaFlags = wpaFlags.concat(parts[1].replace(')', '').split(','));
338
+ }
339
+ });
340
+
341
+ */
342
+ function parseWifiDarwin(wifiObj) {
343
+ const result = [];
344
+ if (wifiObj) {
345
+ wifiObj.forEach(function (wifiItem) {
346
+ const signalLevel = wifiItem.RSSI;
347
+ let security = [];
348
+ let wpaFlags = [];
349
+ if (wifiItem.WPA_IE) {
350
+ security.push('WPA');
351
+ if (wifiItem.WPA_IE.IE_KEY_WPA_UCIPHERS) {
352
+ wifiItem.WPA_IE.IE_KEY_WPA_UCIPHERS.forEach(function (ciphers) {
353
+ if (ciphers === 0 && wpaFlags.indexOf('unknown/TKIP') === -1) { wpaFlags.push('unknown/TKIP'); }
354
+ if (ciphers === 2 && wpaFlags.indexOf('PSK/TKIP') === -1) { wpaFlags.push('PSK/TKIP'); }
355
+ if (ciphers === 4 && wpaFlags.indexOf('PSK/AES') === -1) { wpaFlags.push('PSK/AES'); }
356
+ });
357
+ }
358
+ }
359
+ if (wifiItem.RSN_IE) {
360
+ security.push('WPA2');
361
+ if (wifiItem.RSN_IE.IE_KEY_RSN_UCIPHERS) {
362
+ wifiItem.RSN_IE.IE_KEY_RSN_UCIPHERS.forEach(function (ciphers) {
363
+ if (ciphers === 0 && wpaFlags.indexOf('unknown/TKIP') === -1) { wpaFlags.push('unknown/TKIP'); }
364
+ if (ciphers === 2 && wpaFlags.indexOf('TKIP/TKIP') === -1) { wpaFlags.push('TKIP/TKIP'); }
365
+ if (ciphers === 4 && wpaFlags.indexOf('PSK/AES') === -1) { wpaFlags.push('PSK/AES'); }
366
+ });
367
+ }
368
+ }
369
+ result.push({
370
+ ssid: wifiItem.SSID_STR,
371
+ bssid: wifiItem.BSSID,
372
+ mode: '',
373
+ channel: wifiItem.CHANNEL,
374
+ frequency: wifiFrequencyFromChannel(wifiItem.CHANNEL),
375
+ signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
376
+ quality: wifiQualityFromDB(signalLevel),
377
+ security,
378
+ wpaFlags,
379
+ rsnFlags: []
380
+
381
+ });
382
+ wifiItem.BSSID;
319
383
 
384
+ });
385
+ }
386
+ return result;
387
+ }
388
+ function wifiNetworks(callback) {
320
389
  return new Promise((resolve) => {
321
390
  process.nextTick(() => {
322
391
  let result = [];
@@ -369,45 +438,10 @@ function wifiNetworks(callback) {
369
438
  resolve(result);
370
439
  }
371
440
  } else if (_darwin) {
372
- let cmd = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s';
373
- exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
374
- const lines = stdout.toString().split(os.EOL);
375
- if (lines && lines.length > 1) {
376
- const parsedhead = util.parseHead(lines[0], 1);
377
- if (parsedhead.length >= 7) {
378
- lines.shift();
379
- lines.forEach(line => {
380
- if (line.trim()) {
381
- const channelStr = line.substring(parsedhead[3].from, parsedhead[3].to).trim();
382
- const channel = channelStr ? parseInt(channelStr, 10) : null;
383
- const signalLevel = line.substring(parsedhead[2].from, parsedhead[2].to).trim();
384
- const securityAll = line.substring(parsedhead[6].from, 1000).trim().split(' ');
385
- let security = [];
386
- let wpaFlags = [];
387
- securityAll.forEach(securitySingle => {
388
- if (securitySingle.indexOf('(') > 0) {
389
- const parts = securitySingle.split('(');
390
- security.push(parts[0]);
391
- wpaFlags = wpaFlags.concat(parts[1].replace(')', '').split(','));
392
- }
393
- });
394
- wpaFlags = Array.from(new Set(wpaFlags));
395
- result.push({
396
- ssid: line.substring(parsedhead[0].from, parsedhead[0].to).trim(),
397
- bssid: line.substring(parsedhead[1].from, parsedhead[1].to).trim().toLowerCase(),
398
- mode: '',
399
- channel,
400
- frequency: wifiFrequencyFromChannel(channel),
401
- signalLevel: signalLevel ? parseInt(signalLevel, 10) : null,
402
- quality: wifiQualityFromDB(signalLevel),
403
- security,
404
- wpaFlags,
405
- rsnFlags: []
406
- });
407
- }
408
- });
409
- }
410
- }
441
+ let cmd = '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s -x';
442
+ exec(cmd, { maxBuffer: 1024 * 40000 }, function (error, stdout) {
443
+ const output = stdout.toString();
444
+ result = parseWifiDarwin(util.plistParser(output));
411
445
  if (callback) {
412
446
  callback(result);
413
447
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.9.13",
3
+ "version": "5.9.17",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",