systeminformation 5.10.4 → 5.11.0

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/README.md CHANGED
@@ -101,6 +101,7 @@ si.cpu()
101
101
 
102
102
  (last 7 major and minor version releases)
103
103
 
104
+ - Version 5.11.0: `networkInterfaces()` added default property and default parameter
104
105
  - Version 5.10.0: basic `android` support
105
106
  - Version 5.9.0: `graphics()` added properties (macOS)
106
107
  - Version 5.8.0: `disksIO()` added waitTime, waitPercent (linux)
@@ -381,10 +382,10 @@ Full function reference with examples can be found at [https://systeminformation
381
382
  | | ...[0].pid | X | X | X | X | X | process PID |
382
383
  | | ...[0].parentPid | X | X | X | X | X | parent process PID |
383
384
  | | ...[0].name | X | X | X | X | X | process name |
384
- | | ...[0].pcpu | X | X | X | X | X | process % CPU usage |
385
- | | ...[0].pcpuu | X | X | | X | | process % CPU usage (user) |
386
- | | ...[0].pcpus | X | X | | X | | process % CPU usage (system) |
387
- | | ...[0].pmem | X | X | X | X | X | process memory % |
385
+ | | ...[0].cpu | X | X | X | X | X | process % CPU usage |
386
+ | | ...[0].cpuu | X | X | | X | | process % CPU usage (user) |
387
+ | | ...[0].cpus | X | X | | X | | process % CPU usage (system) |
388
+ | | ...[0].mem | X | X | X | X | X | process memory % |
388
389
  | | ...[0].priority | X | X | X | X | X | process priotity |
389
390
  | | ...[0].memVsz | X | X | X | X | X | process virtual memory size |
390
391
  | | ...[0].memRss | X | X | X | X | X | process mem resident set size |
@@ -539,9 +540,10 @@ Full function reference with examples can be found at [https://systeminformation
539
540
 
540
541
  | Function | Result object | Linux | BSD | Mac | Win | Sun | Comments |
541
542
  | --------------- | ------------- | ----- | ------- | --- | --- | --- | -------- |
542
- | si.networkInterfaces(cb) | [{...}] | X | X | X | X | X | array of network interfaces |
543
+ | si.networkInterfaces(cb) | [{...}] | X | X | X | X | X | array of network interfaces<br>With the 'default' parameter it returns<br>only the default interface |
543
544
  | | [0].iface | X | X | X | X | X | interface |
544
545
  | | [0].ifaceName | X | X | X | X | X | interface name (differs on Windows) |
546
+ | | [0].default | X | X | X | X | X | true if this is the default interface |
545
547
  | | [0].ip4 | X | X | X | X | X | ip4 address |
546
548
  | | [0].ip4subnet | X | X | X | X | X | ip4 subnet mask |
547
549
  | | [0].ip6 | X | X | X | X | X | ip6 address |
package/lib/network.js CHANGED
@@ -692,17 +692,29 @@ function testVirtualNic(iface, ifaceName, mac) {
692
692
  } else { return false; }
693
693
  }
694
694
 
695
- function networkInterfaces(callback, rescan) {
695
+ function networkInterfaces(callback, rescan, defaultString) {
696
+
697
+ if (typeof callback === 'string') {
698
+ defaultString = callback;
699
+ rescan = true;
700
+ callback = null;
701
+ }
696
702
 
697
703
  if (typeof callback === 'boolean') {
698
704
  rescan = callback;
699
705
  callback = null;
706
+ defaultString = '';
700
707
  }
701
708
  if (typeof rescan === 'undefined') {
702
709
  rescan = true;
703
710
  }
711
+ defaultString = defaultString || '';
712
+ defaultString = '' + defaultString;
713
+
704
714
  return new Promise((resolve) => {
705
715
  process.nextTick(() => {
716
+ const defaultInterface = getDefaultNetworkInterface();
717
+
706
718
  let ifaces = os.networkInterfaces();
707
719
 
708
720
  let result = [];
@@ -730,6 +742,7 @@ function networkInterfaces(callback, rescan) {
730
742
  result.push({
731
743
  iface: nic.iface,
732
744
  ifaceName: nic.iface,
745
+ default: nic.iface === defaultInterface,
733
746
  ip4: nic.ip4,
734
747
  ip4subnet: nic.ip4subnet || '',
735
748
  ip6: nic.ip6,
@@ -750,6 +763,14 @@ function networkInterfaces(callback, rescan) {
750
763
  });
751
764
  });
752
765
  _networkInterfaces = result;
766
+ if (defaultString.toLowerCase().indexOf('default') >= 0) {
767
+ result = result.filter(item => item.default);
768
+ if (result.length > 0) {
769
+ result = result[0];
770
+ } else {
771
+ result = [];
772
+ }
773
+ }
753
774
  if (callback) { callback(result); }
754
775
  resolve(result);
755
776
  }
@@ -863,6 +884,7 @@ function networkInterfaces(callback, rescan) {
863
884
  result.push({
864
885
  iface,
865
886
  ifaceName,
887
+ default: iface === defaultInterface,
866
888
  ip4,
867
889
  ip4subnet,
868
890
  ip6,
@@ -884,6 +906,14 @@ function networkInterfaces(callback, rescan) {
884
906
  }
885
907
  }
886
908
  _networkInterfaces = result;
909
+ if (defaultString.toLowerCase().indexOf('default') >= 0) {
910
+ result = result.filter(item => item.default);
911
+ if (result.length > 0) {
912
+ result = result[0];
913
+ } else {
914
+ result = [];
915
+ }
916
+ }
887
917
  if (callback) { callback(result); }
888
918
  resolve(result);
889
919
  }
@@ -990,6 +1020,7 @@ function networkInterfaces(callback, rescan) {
990
1020
  result.push({
991
1021
  iface,
992
1022
  ifaceName,
1023
+ default: iface === defaultInterface,
993
1024
  ip4,
994
1025
  ip4subnet,
995
1026
  ip6,
@@ -1011,6 +1042,14 @@ function networkInterfaces(callback, rescan) {
1011
1042
  }
1012
1043
  }
1013
1044
  _networkInterfaces = result;
1045
+ if (defaultString.toLowerCase().indexOf('default') >= 0) {
1046
+ result = result.filter(item => item.default);
1047
+ if (result.length > 0) {
1048
+ result = result[0];
1049
+ } else {
1050
+ result = [];
1051
+ }
1052
+ }
1014
1053
  if (callback) { callback(result); }
1015
1054
  resolve(result);
1016
1055
  });
package/lib/processes.js CHANGED
@@ -324,13 +324,13 @@ function services(srv, callback) {
324
324
  }
325
325
  if (_windows) {
326
326
  try {
327
- let wincommand = "Get-WmiObject Win32_Service";
327
+ let wincommand = 'Get-WmiObject Win32_Service';
328
328
  if (srvs[0] !== '*') {
329
329
  wincommand += ' -Filter "';
330
330
  for (let i = 0; i < srvs.length; i++) {
331
331
  wincommand += `Name='${srvs[i]}' or `;
332
332
  }
333
- wincommand = `${wincommand.slice(0,-4)}"`;
333
+ wincommand = `${wincommand.slice(0, -4)}"`;
334
334
  }
335
335
  wincommand += ' | fl *';
336
336
  util.powerShell(wincommand).then((stdout, error) => {
@@ -803,8 +803,10 @@ function processes(callback) {
803
803
  let procs = [];
804
804
  let procStats = [];
805
805
  let list_new = {};
806
- let allcpuu = _processes_cpu.all_utime;
807
- let allcpus = _processes_cpu.all_stime;
806
+ let allcpuu = 0;
807
+ let allcpus = 0;
808
+ // let allcpuu = _processes_cpu.all_utime;
809
+ // let allcpus = _processes_cpu.all_stime;
808
810
  for (let i = 0; i < processSections.length; i++) {
809
811
  if (processSections[i].trim() !== '') {
810
812
  let lines = processSections[i].trim().split('\r\n');
@@ -819,6 +821,8 @@ function processes(callback) {
819
821
  let memw = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
820
822
  allcpuu = allcpuu + utime;
821
823
  allcpus = allcpus + stime;
824
+ // allcpuu += utime - (_processes_cpu.list[pid] ? _processes_cpu.list[pid].utime : 0);
825
+ // allcpus += stime - (_processes_cpu.list[pid] ? _processes_cpu.list[pid].stime : 0);
822
826
  result.all++;
823
827
  if (!statusValue) { result.unknown++; }
824
828
  if (statusValue === '3') { result.running++; }
@@ -970,8 +974,10 @@ function processLoad(proc, callback) {
970
974
  let processSections = stdout.split(/\n\s*\n/);
971
975
  let procStats = [];
972
976
  let list_new = {};
973
- let allcpuu = _process_cpu.all_utime;
974
- let allcpus = _process_cpu.all_stime;
977
+ let allcpuu = 0;
978
+ let allcpus = 0;
979
+ // let allcpuu = _process_cpu.all_utime;
980
+ // let allcpus = _process_cpu.all_stime;
975
981
 
976
982
  // go through all processes
977
983
  for (let i = 0; i < processSections.length; i++) {
@@ -984,6 +990,8 @@ function processLoad(proc, callback) {
984
990
  let mem = parseInt(util.getValue(lines, 'WorkingSetSize', ':', true), 10);
985
991
  allcpuu = allcpuu + utime;
986
992
  allcpus = allcpus + stime;
993
+ // allcpuu += utime - (_process_cpu.list[pid] ? _process_cpu.list[pid].utime : 0);
994
+ // allcpus += stime - (_process_cpu.list[pid] ? _process_cpu.list[pid].stime : 0);
987
995
 
988
996
  procStats.push({
989
997
  pid: pid,
package/lib/usb.js CHANGED
@@ -263,7 +263,7 @@ function usb(callback) {
263
263
  });
264
264
  }
265
265
  if (_windows) {
266
- util.powerShell('Get-WmiObject CIM_LogicalDevice | where { $_.Description -match "^USB"}').then((stdout, error) => {
266
+ util.powerShell('Get-WmiObject CIM_LogicalDevice | where { $_.Description -match "USB"}').then((stdout, error) => {
267
267
  if (!error) {
268
268
  const parts = stdout.toString().split(/\n\s*\n/);
269
269
  for (let i = 0; i < parts.length; i++) {
package/lib/users.js CHANGED
@@ -176,44 +176,6 @@ function parseUsersDarwin(lines) {
176
176
  return result;
177
177
  }
178
178
 
179
- // function parseUsersWin(lines, culture) {
180
-
181
- // let result = [];
182
- // const header = lines[0];
183
- // const headerDelimiter = [];
184
- // if (header) {
185
- // const start = (header[0] === ' ') ? 1 : 0;
186
- // headerDelimiter.push(start - 1);
187
- // let nextSpace = 0;
188
- // for (let i = start + 1; i < header.length; i++) {
189
- // if (header[i] === ' ' && ((header[i - 1] === ' ') || (header[i - 1] === '.'))) {
190
- // nextSpace = i;
191
- // } else {
192
- // if (nextSpace) {
193
- // headerDelimiter.push(nextSpace);
194
- // nextSpace = 0;
195
- // }
196
- // }
197
- // }
198
- // for (let i = 1; i < lines.length; i++) {
199
- // if (lines[i].trim()) {
200
- // const user = lines[i].substring(headerDelimiter[0] + 1, headerDelimiter[1]).trim() || '';
201
- // const tty = lines[i].substring(headerDelimiter[1] + 1, headerDelimiter[2] - 2).trim() || '';
202
- // const dateTime = util.parseDateTime(lines[i].substring(headerDelimiter[5] + 1, 2000).trim(), culture) || '';
203
- // result.push({
204
- // user: user,
205
- // tty: tty,
206
- // date: dateTime.date,
207
- // time: dateTime.time,
208
- // ip: '',
209
- // command: ''
210
- // });
211
- // }
212
- // }
213
- // }
214
- // return result;
215
- // }
216
-
217
179
  function users(callback) {
218
180
 
219
181
  return new Promise((resolve) => {
@@ -293,7 +255,8 @@ function users(callback) {
293
255
  // ).then(data => {
294
256
  let cmd = 'Get-WmiObject Win32_LogonSession | fl *' + '; echo \'#-#-#-#\';';
295
257
  cmd += 'Get-WmiObject Win32_LoggedOnUser | fl *' + '; echo \'#-#-#-#\';';
296
- cmd += 'Get-WmiObject Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl';
258
+ cmd += 'Get-WmiObject Win32_Process -Filter "name=\'explorer.exe\'" | Select @{Name="sessionid";Expression={$_.SessionId}}, @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl' + '; echo \'#-#-#-#\';';
259
+ cmd += 'query user';
297
260
  util.powerShell(cmd).then(data => {
298
261
  // controller + vram
299
262
  // let accounts = parseWinAccounts(data[0].split(/\n\s*\n/));
@@ -301,7 +264,8 @@ function users(callback) {
301
264
  data = data.split('#-#-#-#');
302
265
  let sessions = parseWinSessions(data[0].split(/\n\s*\n/));
303
266
  let loggedons = parseWinLoggedOn(data[1].split(/\n\s*\n/));
304
- let users = parseWinUsers(data[2].split(/\n\s*\n/));
267
+ let queryUser = parseWinUsersQuery(data[3].split('\r\n'));
268
+ let users = parseWinUsers(data[2].split(/\n\s*\n/), queryUser);
305
269
  for (let id in loggedons) {
306
270
  if ({}.hasOwnProperty.call(loggedons, id)) {
307
271
  loggedons[id].dateTime = {}.hasOwnProperty.call(sessions, id) ? sessions[id] : '';
@@ -319,7 +283,7 @@ function users(callback) {
319
283
 
320
284
  result.push({
321
285
  user: user.user,
322
- tty: '',
286
+ tty: user.tty,
323
287
  date: `${dateTime.substr(0, 4)}-${dateTime.substr(4, 2)}-${dateTime.substr(6, 2)}`,
324
288
  time: `${dateTime.substr(8, 2)}:${dateTime.substr(10, 2)}`,
325
289
  ip: '',
@@ -380,17 +344,36 @@ function parseWinSessions(sessionParts) {
380
344
  return sessions;
381
345
  }
382
346
 
383
- function parseWinUsers(userParts) {
347
+ function fuzzyMatch(name1, name2) {
348
+ name1 = name1.toLowerCase();
349
+ name2 = name2.toLowerCase();
350
+ let eq = 0;
351
+ let len = name1.length;
352
+ if (name2.length > len) { len = name2.length; }
353
+
354
+ for (let i = 0; i < len; i++) {
355
+ const c1 = name1[i] || '';
356
+ const c2 = name2[i] || '';
357
+ if (c1 === c2) { eq++; }
358
+ }
359
+ return (len > 10 ? eq / len > 0.9 : (len > 0 ? eq / len > 0.8 : false));
360
+ }
361
+
362
+ function parseWinUsers(userParts, userQuery) {
384
363
  const users = [];
385
364
  userParts.forEach(user => {
386
365
  const lines = user.split('\r\n');
387
366
 
388
367
  const domain = util.getValue(lines, 'domain', ':', true);
389
368
  const username = util.getValue(lines, 'username', ':', true);
369
+ const sessionid = util.getValue(lines, 'sessionid', ':', true);
370
+
390
371
  if (username) {
372
+ const quser = userQuery.filter(item => fuzzyMatch(item.user, username));
391
373
  users.push({
392
374
  domain,
393
- user: username
375
+ user: username,
376
+ tty: quser && quser[0] && quser[0].tty ? quser[0].tty : sessionid
394
377
  });
395
378
  }
396
379
  });
@@ -421,4 +404,38 @@ function parseWinLoggedOn(loggedonParts) {
421
404
  return loggedons;
422
405
  }
423
406
 
407
+ function parseWinUsersQuery(lines) {
408
+ lines = lines.filter(item => item);
409
+ let result = [];
410
+ const header = lines[0];
411
+ const headerDelimiter = [];
412
+ if (header) {
413
+ const start = (header[0] === ' ') ? 1 : 0;
414
+ headerDelimiter.push(start - 1);
415
+ let nextSpace = 0;
416
+ for (let i = start + 1; i < header.length; i++) {
417
+ if (header[i] === ' ' && ((header[i - 1] === ' ') || (header[i - 1] === '.'))) {
418
+ nextSpace = i;
419
+ } else {
420
+ if (nextSpace) {
421
+ headerDelimiter.push(nextSpace);
422
+ nextSpace = 0;
423
+ }
424
+ }
425
+ }
426
+ for (let i = 1; i < lines.length; i++) {
427
+ if (lines[i].trim()) {
428
+ const user = lines[i].substring(headerDelimiter[0] + 1, headerDelimiter[1]).trim() || '';
429
+ const tty = lines[i].substring(headerDelimiter[1] + 1, headerDelimiter[2] - 2).trim() || '';
430
+ // const dateTime = util.parseDateTime(lines[i].substring(headerDelimiter[5] + 1, 2000).trim(), culture) || '';
431
+ result.push({
432
+ user: user,
433
+ tty: tty,
434
+ });
435
+ }
436
+ }
437
+ }
438
+ return result;
439
+ }
440
+
424
441
  exports.users = users;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.10.4",
3
+ "version": "5.11.0",
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)",