systeminformation 5.28.0 → 5.28.2
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 +16 -10
- package/lib/graphics.js +1 -1
- package/lib/index.js +35 -30
- package/lib/network.js +142 -81
- package/lib/osinfo.js +128 -144
- package/lib/processes.js +445 -325
- package/lib/util.js +4 -4
- package/package.json +1 -1
package/lib/network.js
CHANGED
|
@@ -19,7 +19,7 @@ const execSync = require('child_process').execSync;
|
|
|
19
19
|
const fs = require('fs');
|
|
20
20
|
const util = require('./util');
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const _platform = process.platform;
|
|
23
23
|
|
|
24
24
|
const _linux = _platform === 'linux' || _platform === 'android';
|
|
25
25
|
const _darwin = _platform === 'darwin';
|
|
@@ -29,7 +29,7 @@ const _openbsd = _platform === 'openbsd';
|
|
|
29
29
|
const _netbsd = _platform === 'netbsd';
|
|
30
30
|
const _sunos = _platform === 'sunos';
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
const _network = {};
|
|
33
33
|
let _default_iface = '';
|
|
34
34
|
let _ifaces = {};
|
|
35
35
|
let _dhcpNics = [];
|
|
@@ -41,14 +41,14 @@ function getDefaultNetworkInterface() {
|
|
|
41
41
|
let ifacename = '';
|
|
42
42
|
let ifacenameFirst = '';
|
|
43
43
|
try {
|
|
44
|
-
|
|
44
|
+
const ifaces = os.networkInterfaces();
|
|
45
45
|
|
|
46
46
|
let scopeid = 9999;
|
|
47
47
|
|
|
48
48
|
// fallback - "first" external interface (sorted by scopeid)
|
|
49
49
|
for (let dev in ifaces) {
|
|
50
50
|
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
|
51
|
-
ifaces[dev].forEach(
|
|
51
|
+
ifaces[dev].forEach((details) => {
|
|
52
52
|
if (details && details.internal === false) {
|
|
53
53
|
ifacenameFirst = ifacenameFirst || dev; // fallback if no scopeid
|
|
54
54
|
if (details.scopeid && details.scopeid < scopeid) {
|
|
@@ -79,7 +79,7 @@ function getDefaultNetworkInterface() {
|
|
|
79
79
|
if (defaultIp) {
|
|
80
80
|
for (let dev in ifaces) {
|
|
81
81
|
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
|
82
|
-
ifaces[dev].forEach(
|
|
82
|
+
ifaces[dev].forEach((details) => {
|
|
83
83
|
if (details && details.address && details.address === defaultIp) {
|
|
84
84
|
ifacename = dev;
|
|
85
85
|
}
|
|
@@ -89,9 +89,9 @@ function getDefaultNetworkInterface() {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
if (_linux) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const cmd = 'ip route 2> /dev/null | grep default';
|
|
93
|
+
const result = execSync(cmd, util.execOptsLinux);
|
|
94
|
+
const parts = result.toString().split('\n')[0].split(/\s+/);
|
|
95
95
|
if (parts[0] === 'none' && parts[5]) {
|
|
96
96
|
ifacename = parts[5];
|
|
97
97
|
} else if (parts[4]) {
|
|
@@ -113,7 +113,7 @@ function getDefaultNetworkInterface() {
|
|
|
113
113
|
if (_freebsd || _openbsd || _netbsd || _sunos) {
|
|
114
114
|
cmd = 'route get 0.0.0.0 | grep interface:';
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
const result = execSync(cmd);
|
|
117
117
|
ifacename = result.toString().split('\n')[0];
|
|
118
118
|
if (ifacename.indexOf(':') > -1) {
|
|
119
119
|
ifacename = ifacename.split(':')[1].trim();
|
|
@@ -133,7 +133,7 @@ exports.getDefaultNetworkInterface = getDefaultNetworkInterface;
|
|
|
133
133
|
function getMacAddresses() {
|
|
134
134
|
let iface = '';
|
|
135
135
|
let mac = '';
|
|
136
|
-
|
|
136
|
+
const result = {};
|
|
137
137
|
if (_linux || _freebsd || _openbsd || _netbsd) {
|
|
138
138
|
if (typeof pathToIp === 'undefined') {
|
|
139
139
|
try {
|
|
@@ -149,12 +149,12 @@ function getMacAddresses() {
|
|
|
149
149
|
}
|
|
150
150
|
try {
|
|
151
151
|
const cmd = 'export LC_ALL=C; ' + (pathToIp ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL';
|
|
152
|
-
|
|
152
|
+
const res = execSync(cmd, util.execOptsLinux);
|
|
153
153
|
const lines = res.toString().split('\n');
|
|
154
154
|
for (let i = 0; i < lines.length; i++) {
|
|
155
155
|
if (lines[i] && lines[i][0] !== ' ') {
|
|
156
156
|
if (pathToIp) {
|
|
157
|
-
|
|
157
|
+
const nextline = lines[i + 1].trim().split(' ');
|
|
158
158
|
if (nextline[0] === 'link/ether') {
|
|
159
159
|
iface = lines[i].split(' ')[1];
|
|
160
160
|
iface = iface.slice(0, iface.length - 1);
|
|
@@ -203,7 +203,7 @@ function getMacAddresses() {
|
|
|
203
203
|
function networkInterfaceDefault(callback) {
|
|
204
204
|
return new Promise((resolve) => {
|
|
205
205
|
process.nextTick(() => {
|
|
206
|
-
|
|
206
|
+
const result = getDefaultNetworkInterface();
|
|
207
207
|
if (callback) {
|
|
208
208
|
callback(result);
|
|
209
209
|
}
|
|
@@ -218,7 +218,7 @@ exports.networkInterfaceDefault = networkInterfaceDefault;
|
|
|
218
218
|
// NET - interfaces
|
|
219
219
|
|
|
220
220
|
function parseLinesWindowsNics(sections, nconfigsections) {
|
|
221
|
-
|
|
221
|
+
const nics = [];
|
|
222
222
|
for (let i in sections) {
|
|
223
223
|
try {
|
|
224
224
|
if ({}.hasOwnProperty.call(sections, i)) {
|
|
@@ -230,10 +230,10 @@ function parseLinesWindowsNics(sections, nconfigsections) {
|
|
|
230
230
|
} catch (e) {
|
|
231
231
|
util.noop();
|
|
232
232
|
}
|
|
233
|
-
|
|
233
|
+
const netEnabled = util.getValue(lines, 'NetEnabled', ':');
|
|
234
234
|
let adapterType = util.getValue(lines, 'AdapterTypeID', ':') === '9' ? 'wireless' : 'wired';
|
|
235
|
-
|
|
236
|
-
|
|
235
|
+
const ifacename = util.getValue(lines, 'Name', ':').replace(/\]/g, ')').replace(/\[/g, '(');
|
|
236
|
+
const iface = util.getValue(lines, 'NetConnectionID', ':').replace(/\]/g, ')').replace(/\[/g, '(');
|
|
237
237
|
if (ifacename.toLowerCase().indexOf('wi-fi') >= 0 || ifacename.toLowerCase().indexOf('wireless') >= 0) {
|
|
238
238
|
adapterType = 'wireless';
|
|
239
239
|
}
|
|
@@ -448,7 +448,7 @@ function getWindowsIEEE8021x(connectionType, iface, ifaces) {
|
|
|
448
448
|
function splitSectionsNics(lines) {
|
|
449
449
|
const result = [];
|
|
450
450
|
let section = [];
|
|
451
|
-
lines.forEach(
|
|
451
|
+
lines.forEach((line) => {
|
|
452
452
|
if (!line.startsWith('\t') && !line.startsWith(' ')) {
|
|
453
453
|
if (section.length) {
|
|
454
454
|
result.push(section);
|
|
@@ -480,7 +480,7 @@ function parseLinesDarwinNics(sections) {
|
|
|
480
480
|
};
|
|
481
481
|
const first = section[0];
|
|
482
482
|
nic.iface = first.split(':')[0].trim();
|
|
483
|
-
|
|
483
|
+
const parts = first.split('> mtu');
|
|
484
484
|
nic.mtu = parts.length > 1 ? parseInt(parts[1], 10) : null;
|
|
485
485
|
if (isNaN(nic.mtu)) {
|
|
486
486
|
nic.mtu = null;
|
|
@@ -524,12 +524,12 @@ function parseLinesDarwinNics(sections) {
|
|
|
524
524
|
function getDarwinNics() {
|
|
525
525
|
const cmd = '/sbin/ifconfig -v';
|
|
526
526
|
try {
|
|
527
|
-
const lines = execSync(cmd, { maxBuffer: 1024 *
|
|
527
|
+
const lines = execSync(cmd, { maxBuffer: 1024 * 102400 })
|
|
528
528
|
.toString()
|
|
529
529
|
.split('\n');
|
|
530
530
|
const nsections = splitSectionsNics(lines);
|
|
531
531
|
return parseLinesDarwinNics(nsections);
|
|
532
|
-
} catch
|
|
532
|
+
} catch {
|
|
533
533
|
return [];
|
|
534
534
|
}
|
|
535
535
|
}
|
|
@@ -543,7 +543,7 @@ function getLinuxIfaceConnectionName(interfaceName) {
|
|
|
543
543
|
const connectionNameLines = resultFormat.split(' ').slice(3);
|
|
544
544
|
const connectionName = connectionNameLines.join(' ');
|
|
545
545
|
return connectionName !== '--' ? connectionName : '';
|
|
546
|
-
} catch
|
|
546
|
+
} catch {
|
|
547
547
|
return '';
|
|
548
548
|
}
|
|
549
549
|
}
|
|
@@ -562,11 +562,11 @@ function checkLinuxDCHPInterfaces(file) {
|
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
if (line.toLowerCase().includes('source')) {
|
|
565
|
-
|
|
565
|
+
const file = line.split(' ')[1];
|
|
566
566
|
result = result.concat(checkLinuxDCHPInterfaces(file));
|
|
567
567
|
}
|
|
568
568
|
});
|
|
569
|
-
} catch
|
|
569
|
+
} catch {
|
|
570
570
|
util.noop();
|
|
571
571
|
}
|
|
572
572
|
return result;
|
|
@@ -574,18 +574,18 @@ function checkLinuxDCHPInterfaces(file) {
|
|
|
574
574
|
|
|
575
575
|
function getLinuxDHCPNics() {
|
|
576
576
|
// alternate methods getting interfaces using DHCP
|
|
577
|
-
|
|
577
|
+
const cmd = 'ip a 2> /dev/null';
|
|
578
578
|
let result = [];
|
|
579
579
|
try {
|
|
580
580
|
const lines = execSync(cmd, util.execOptsLinux).toString().split('\n');
|
|
581
581
|
const nsections = splitSectionsNics(lines);
|
|
582
582
|
result = parseLinuxDHCPNics(nsections);
|
|
583
|
-
} catch
|
|
583
|
+
} catch {
|
|
584
584
|
util.noop();
|
|
585
585
|
}
|
|
586
586
|
try {
|
|
587
587
|
result = checkLinuxDCHPInterfaces('/etc/network/interfaces');
|
|
588
|
-
} catch
|
|
588
|
+
} catch {
|
|
589
589
|
util.noop();
|
|
590
590
|
}
|
|
591
591
|
return result;
|
|
@@ -621,7 +621,7 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
|
|
|
621
621
|
const lines = execSync(cmd, util.execOptsLinux).toString();
|
|
622
622
|
const resultFormat = lines.replace(/\s+/g, ' ').trim();
|
|
623
623
|
|
|
624
|
-
|
|
624
|
+
const dhcStatus = resultFormat.split(' ').slice(1).toString();
|
|
625
625
|
switch (dhcStatus) {
|
|
626
626
|
case 'auto':
|
|
627
627
|
result = true;
|
|
@@ -632,7 +632,7 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
|
|
|
632
632
|
break;
|
|
633
633
|
}
|
|
634
634
|
return result;
|
|
635
|
-
} catch
|
|
635
|
+
} catch {
|
|
636
636
|
return DHCPNics.indexOf(iface) >= 0;
|
|
637
637
|
}
|
|
638
638
|
} else {
|
|
@@ -648,7 +648,7 @@ function getDarwinIfaceDHCPstatus(iface) {
|
|
|
648
648
|
if (lines.length && lines[0].startsWith('lease_time')) {
|
|
649
649
|
result = true;
|
|
650
650
|
}
|
|
651
|
-
} catch
|
|
651
|
+
} catch {
|
|
652
652
|
util.noop();
|
|
653
653
|
}
|
|
654
654
|
return result;
|
|
@@ -662,7 +662,7 @@ function getLinuxIfaceDNSsuffix(connectionName) {
|
|
|
662
662
|
const resultFormat = result.replace(/\s+/g, ' ').trim();
|
|
663
663
|
const dnsSuffix = resultFormat.split(' ').slice(1).toString();
|
|
664
664
|
return dnsSuffix === '--' ? 'Not defined' : dnsSuffix;
|
|
665
|
-
} catch
|
|
665
|
+
} catch {
|
|
666
666
|
return 'Unknown';
|
|
667
667
|
}
|
|
668
668
|
} else {
|
|
@@ -679,7 +679,7 @@ function getLinuxIfaceIEEE8021xAuth(connectionName) {
|
|
|
679
679
|
const authenticationProtocol = resultFormat.split(' ').slice(1).toString();
|
|
680
680
|
|
|
681
681
|
return authenticationProtocol === '--' ? '' : authenticationProtocol;
|
|
682
|
-
} catch
|
|
682
|
+
} catch {
|
|
683
683
|
return 'Not defined';
|
|
684
684
|
}
|
|
685
685
|
} else {
|
|
@@ -762,7 +762,7 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
762
762
|
|
|
763
763
|
return new Promise((resolve) => {
|
|
764
764
|
process.nextTick(() => {
|
|
765
|
-
|
|
765
|
+
const ifaces = os.networkInterfaces();
|
|
766
766
|
|
|
767
767
|
let result = [];
|
|
768
768
|
let nics = [];
|
|
@@ -785,16 +785,44 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
785
785
|
nics = getDarwinNics();
|
|
786
786
|
|
|
787
787
|
nics.forEach((nic) => {
|
|
788
|
+
let ip4link = '';
|
|
789
|
+
let ip4linksubnet = '';
|
|
790
|
+
let ip6link = '';
|
|
791
|
+
let ip6linksubnet = '';
|
|
792
|
+
nic.ip4 = '';
|
|
793
|
+
nic.ip6 = '';
|
|
788
794
|
if ({}.hasOwnProperty.call(ifaces, nic.iface)) {
|
|
789
795
|
ifaces[nic.iface].forEach((details) => {
|
|
790
796
|
if (details.family === 'IPv4' || details.family === 4) {
|
|
791
|
-
nic.
|
|
797
|
+
if (!nic.ip4 && !nic.ip4.match(/^169.254/i)) {
|
|
798
|
+
nic.ip4 = details.address;
|
|
799
|
+
nic.ip4subnet = details.netmask;
|
|
800
|
+
}
|
|
801
|
+
if (nic.ip4.match(/^169.254/i)) {
|
|
802
|
+
ip4link = details.address;
|
|
803
|
+
ip4linksubnet = details.netmask;
|
|
804
|
+
}
|
|
792
805
|
}
|
|
793
806
|
if (details.family === 'IPv6' || details.family === 6) {
|
|
794
|
-
nic.
|
|
807
|
+
if (!nic.ip6 && !nic.ip6.match(/^fe80::/i)) {
|
|
808
|
+
nic.ip6 = details.address;
|
|
809
|
+
nic.ip6subnet = details.netmask;
|
|
810
|
+
}
|
|
811
|
+
if (nic.ip6.match(/^fe80::/i)) {
|
|
812
|
+
ip6link = details.address;
|
|
813
|
+
ip6linksubnet = details.netmask;
|
|
814
|
+
}
|
|
795
815
|
}
|
|
796
816
|
});
|
|
797
817
|
}
|
|
818
|
+
if (!nic.ip4 && ip4link) {
|
|
819
|
+
nic.ip4 = ip4link;
|
|
820
|
+
nic.ip4subnet = ip4linksubnet;
|
|
821
|
+
}
|
|
822
|
+
if (!nic.ip6 && ip6link) {
|
|
823
|
+
nic.ip6 = ip6link;
|
|
824
|
+
nic.ip6subnet = ip6linksubnet;
|
|
825
|
+
}
|
|
798
826
|
|
|
799
827
|
let ifaceSanitized = '';
|
|
800
828
|
const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(nic.iface);
|
|
@@ -872,18 +900,33 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
872
900
|
let ieee8021xState = '';
|
|
873
901
|
let type = '';
|
|
874
902
|
|
|
903
|
+
let ip4link = '';
|
|
904
|
+
let ip4linksubnet = '';
|
|
905
|
+
let ip6link = '';
|
|
906
|
+
let ip6linksubnet = '';
|
|
907
|
+
|
|
875
908
|
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
|
876
|
-
|
|
877
|
-
ifaces[dev].forEach(
|
|
909
|
+
const ifaceName = dev;
|
|
910
|
+
ifaces[dev].forEach((details) => {
|
|
878
911
|
if (details.family === 'IPv4' || details.family === 4) {
|
|
879
|
-
ip4
|
|
880
|
-
|
|
912
|
+
if (!ip4 && !ip4.match(/^169.254/i)) {
|
|
913
|
+
ip4 = details.address;
|
|
914
|
+
ip4subnet = details.netmask;
|
|
915
|
+
}
|
|
916
|
+
if (ip4.match(/^169.254/i)) {
|
|
917
|
+
ip4link = details.address;
|
|
918
|
+
ip4linksubnet = details.netmask;
|
|
919
|
+
}
|
|
881
920
|
}
|
|
882
921
|
if (details.family === 'IPv6' || details.family === 6) {
|
|
883
|
-
if (!ip6
|
|
922
|
+
if (!ip6 && !ip6.match(/^fe80::/i)) {
|
|
884
923
|
ip6 = details.address;
|
|
885
924
|
ip6subnet = details.netmask;
|
|
886
925
|
}
|
|
926
|
+
if (ip6.match(/^fe80::/i)) {
|
|
927
|
+
ip6link = details.address;
|
|
928
|
+
ip6linksubnet = details.netmask;
|
|
929
|
+
}
|
|
887
930
|
}
|
|
888
931
|
mac = details.mac;
|
|
889
932
|
// fallback due to https://github.com/nodejs/node/issues/13581 (node 8.1 - node 8.2)
|
|
@@ -895,7 +938,15 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
895
938
|
mac = _mac[dev] || '';
|
|
896
939
|
}
|
|
897
940
|
});
|
|
898
|
-
|
|
941
|
+
if (!ip4 && ip4link) {
|
|
942
|
+
ip4 = ip4link;
|
|
943
|
+
ip4subnet = ip4linksubnet;
|
|
944
|
+
}
|
|
945
|
+
if (!ip6 && ip6link) {
|
|
946
|
+
ip6 = ip6link;
|
|
947
|
+
ip6subnet = ip6linksubnet;
|
|
948
|
+
}
|
|
949
|
+
const iface = dev.split(':')[0].trim().toLowerCase();
|
|
899
950
|
let ifaceSanitized = '';
|
|
900
951
|
const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface);
|
|
901
952
|
const l = util.mathMin(s.length, 2000);
|
|
@@ -1015,7 +1066,7 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
1015
1066
|
_ifaces = JSON.parse(JSON.stringify(ifaces));
|
|
1016
1067
|
const defaultInterface = getDefaultNetworkInterface();
|
|
1017
1068
|
|
|
1018
|
-
getWindowsNics().then(
|
|
1069
|
+
getWindowsNics().then((nics) => {
|
|
1019
1070
|
nics.forEach((nic) => {
|
|
1020
1071
|
let found = false;
|
|
1021
1072
|
Object.keys(ifaces).forEach((key) => {
|
|
@@ -1063,7 +1114,7 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
1063
1114
|
|
|
1064
1115
|
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
|
1065
1116
|
let ifaceName = dev;
|
|
1066
|
-
ifaces[dev].forEach(
|
|
1117
|
+
ifaces[dev].forEach((details) => {
|
|
1067
1118
|
if (details.family === 'IPv4' || details.family === 4) {
|
|
1068
1119
|
ip4 = details.address;
|
|
1069
1120
|
ip4subnet = details.netmask;
|
|
@@ -1168,7 +1219,7 @@ exports.networkInterfaces = networkInterfaces;
|
|
|
1168
1219
|
// NET - Speed
|
|
1169
1220
|
|
|
1170
1221
|
function calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors) {
|
|
1171
|
-
|
|
1222
|
+
const result = {
|
|
1172
1223
|
iface,
|
|
1173
1224
|
operstate,
|
|
1174
1225
|
rx_bytes,
|
|
@@ -1234,7 +1285,7 @@ function networkStats(ifaces, callback) {
|
|
|
1234
1285
|
ifaces.__proto__.substring = util.stringSubstring;
|
|
1235
1286
|
ifaces.__proto__.trim = util.stringTrim;
|
|
1236
1287
|
ifaces.__proto__.startsWith = util.stringStartWith;
|
|
1237
|
-
} catch
|
|
1288
|
+
} catch {
|
|
1238
1289
|
Object.setPrototypeOf(ifaces, util.stringObj);
|
|
1239
1290
|
}
|
|
1240
1291
|
|
|
@@ -1369,7 +1420,7 @@ function networkStatsSingle(iface) {
|
|
|
1369
1420
|
'cat /sys/class/net/' +
|
|
1370
1421
|
ifaceSanitized +
|
|
1371
1422
|
'/statistics/tx_errors; ';
|
|
1372
|
-
exec(cmd,
|
|
1423
|
+
exec(cmd, (error, stdout) => {
|
|
1373
1424
|
if (!error) {
|
|
1374
1425
|
lines = stdout.toString().split('\n');
|
|
1375
1426
|
operstate = lines[0].trim();
|
|
@@ -1390,7 +1441,7 @@ function networkStatsSingle(iface) {
|
|
|
1390
1441
|
}
|
|
1391
1442
|
if (_freebsd || _openbsd || _netbsd) {
|
|
1392
1443
|
cmd = 'netstat -ibndI ' + ifaceSanitized; // lgtm [js/shell-command-constructed-from-input]
|
|
1393
|
-
exec(cmd,
|
|
1444
|
+
exec(cmd, (error, stdout) => {
|
|
1394
1445
|
if (!error) {
|
|
1395
1446
|
lines = stdout.toString().split('\n');
|
|
1396
1447
|
for (let i = 1; i < lines.length; i++) {
|
|
@@ -1420,7 +1471,7 @@ function networkStatsSingle(iface) {
|
|
|
1420
1471
|
}
|
|
1421
1472
|
if (_darwin) {
|
|
1422
1473
|
cmd = 'ifconfig ' + ifaceSanitized + ' | grep "status"'; // lgtm [js/shell-command-constructed-from-input]
|
|
1423
|
-
exec(cmd,
|
|
1474
|
+
exec(cmd, (error, stdout) => {
|
|
1424
1475
|
result.operstate = (stdout.toString().split(':')[1] || '').trim();
|
|
1425
1476
|
result.operstate = (result.operstate || '').toLowerCase();
|
|
1426
1477
|
result.operstate = result.operstate === 'active' ? 'up' : result.operstate === 'inactive' ? 'down' : 'unknown';
|
|
@@ -1551,15 +1602,15 @@ function networkConnections(callback) {
|
|
|
1551
1602
|
cmd =
|
|
1552
1603
|
'export LC_ALL=C; netstat -na | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"; unset LC_ALL';
|
|
1553
1604
|
}
|
|
1554
|
-
exec(cmd, { maxBuffer: 1024 *
|
|
1605
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1555
1606
|
let lines = stdout.toString().split('\n');
|
|
1556
1607
|
if (!error && (lines.length > 1 || lines[0] !== '')) {
|
|
1557
|
-
lines.forEach(
|
|
1608
|
+
lines.forEach((line) => {
|
|
1558
1609
|
line = line.replace(/ +/g, ' ').split(' ');
|
|
1559
1610
|
if (line.length >= 7) {
|
|
1560
1611
|
let localip = line[3];
|
|
1561
1612
|
let localport = '';
|
|
1562
|
-
|
|
1613
|
+
const localaddress = line[3].split(':');
|
|
1563
1614
|
if (localaddress.length > 1) {
|
|
1564
1615
|
localport = localaddress[localaddress.length - 1];
|
|
1565
1616
|
localaddress.pop();
|
|
@@ -1567,14 +1618,14 @@ function networkConnections(callback) {
|
|
|
1567
1618
|
}
|
|
1568
1619
|
let peerip = line[4];
|
|
1569
1620
|
let peerport = '';
|
|
1570
|
-
|
|
1621
|
+
const peeraddress = line[4].split(':');
|
|
1571
1622
|
if (peeraddress.length > 1) {
|
|
1572
1623
|
peerport = peeraddress[peeraddress.length - 1];
|
|
1573
1624
|
peeraddress.pop();
|
|
1574
1625
|
peerip = peeraddress.join(':');
|
|
1575
1626
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1627
|
+
const connstate = line[5];
|
|
1628
|
+
const proc = line[6].split('/');
|
|
1578
1629
|
|
|
1579
1630
|
if (connstate) {
|
|
1580
1631
|
result.push({
|
|
@@ -1596,15 +1647,15 @@ function networkConnections(callback) {
|
|
|
1596
1647
|
resolve(result);
|
|
1597
1648
|
} else {
|
|
1598
1649
|
cmd = 'ss -tunap | grep "ESTAB\\|SYN-SENT\\|SYN-RECV\\|FIN-WAIT1\\|FIN-WAIT2\\|TIME-WAIT\\|CLOSE\\|CLOSE-WAIT\\|LAST-ACK\\|LISTEN\\|CLOSING"';
|
|
1599
|
-
exec(cmd, { maxBuffer: 1024 *
|
|
1650
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1600
1651
|
if (!error) {
|
|
1601
|
-
|
|
1602
|
-
lines.forEach(
|
|
1652
|
+
const lines = stdout.toString().split('\n');
|
|
1653
|
+
lines.forEach((line) => {
|
|
1603
1654
|
line = line.replace(/ +/g, ' ').split(' ');
|
|
1604
1655
|
if (line.length >= 6) {
|
|
1605
1656
|
let localip = line[4];
|
|
1606
1657
|
let localport = '';
|
|
1607
|
-
|
|
1658
|
+
const localaddress = line[4].split(':');
|
|
1608
1659
|
if (localaddress.length > 1) {
|
|
1609
1660
|
localport = localaddress[localaddress.length - 1];
|
|
1610
1661
|
localaddress.pop();
|
|
@@ -1612,7 +1663,7 @@ function networkConnections(callback) {
|
|
|
1612
1663
|
}
|
|
1613
1664
|
let peerip = line[5];
|
|
1614
1665
|
let peerport = '';
|
|
1615
|
-
|
|
1666
|
+
const peeraddress = line[5].split(':');
|
|
1616
1667
|
if (peeraddress.length > 1) {
|
|
1617
1668
|
peerport = peeraddress[peeraddress.length - 1];
|
|
1618
1669
|
peeraddress.pop();
|
|
@@ -1628,12 +1679,22 @@ function networkConnections(callback) {
|
|
|
1628
1679
|
let pid = null;
|
|
1629
1680
|
let process = '';
|
|
1630
1681
|
if (line.length >= 7 && line[6].indexOf('users:') > -1) {
|
|
1631
|
-
|
|
1682
|
+
const proc = line[6].replace('users:(("', '').replace(/"/g, '').replace('pid=', '').split(',');
|
|
1632
1683
|
if (proc.length > 2) {
|
|
1633
|
-
process = proc[0]
|
|
1634
|
-
|
|
1684
|
+
process = proc[0];
|
|
1685
|
+
const pidValue = parseInt(proc[1], 10);
|
|
1686
|
+
if (pidValue > 0) {
|
|
1687
|
+
pid = pidValue;
|
|
1688
|
+
}
|
|
1635
1689
|
}
|
|
1636
1690
|
}
|
|
1691
|
+
// if (line.length >= 7 && line[6].indexOf('users:') > -1) {
|
|
1692
|
+
// const proc = line[6].replace('users:(("', '').replace(/"/g, '').split(',');
|
|
1693
|
+
// if (proc.length > 2) {
|
|
1694
|
+
// process = proc[0].split(' ')[0].split(':')[0];
|
|
1695
|
+
// pid = parseInt(proc[1], 10);
|
|
1696
|
+
// }
|
|
1697
|
+
// }
|
|
1637
1698
|
if (connstate) {
|
|
1638
1699
|
result.push({
|
|
1639
1700
|
protocol: line[0],
|
|
@@ -1658,16 +1719,16 @@ function networkConnections(callback) {
|
|
|
1658
1719
|
});
|
|
1659
1720
|
}
|
|
1660
1721
|
if (_darwin) {
|
|
1661
|
-
|
|
1722
|
+
const cmd = 'netstat -natvln | head -n2; netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"';
|
|
1662
1723
|
const states = 'ESTABLISHED|SYN_SENT|SYN_RECV|FIN_WAIT1|FIN_WAIT_1|FIN_WAIT2|FIN_WAIT_2|TIME_WAIT|CLOSE|CLOSE_WAIT|LAST_ACK|LISTEN|CLOSING|UNKNOWN'.split('|');
|
|
1663
|
-
exec(cmd, { maxBuffer: 1024 *
|
|
1724
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1664
1725
|
if (!error) {
|
|
1665
|
-
exec('ps -axo pid,command', { maxBuffer: 1024 *
|
|
1726
|
+
exec('ps -axo pid,command', { maxBuffer: 1024 * 102400 }, (err2, stdout2) => {
|
|
1666
1727
|
let processes = stdout2.toString().split('\n');
|
|
1667
1728
|
processes = processes.map((line) => {
|
|
1668
1729
|
return line.trim().replace(/ +/g, ' ');
|
|
1669
1730
|
});
|
|
1670
|
-
|
|
1731
|
+
const lines = stdout.toString().split('\n');
|
|
1671
1732
|
lines.shift();
|
|
1672
1733
|
let pidPos = 8;
|
|
1673
1734
|
if (lines.length > 1 && lines[0].indexOf('pid') > 0) {
|
|
@@ -1678,12 +1739,12 @@ function networkConnections(callback) {
|
|
|
1678
1739
|
.split(' ');
|
|
1679
1740
|
pidPos = header.indexOf('pid');
|
|
1680
1741
|
}
|
|
1681
|
-
lines.forEach(
|
|
1742
|
+
lines.forEach((line) => {
|
|
1682
1743
|
line = line.replace(/ +/g, ' ').split(' ');
|
|
1683
1744
|
if (line.length >= 8) {
|
|
1684
1745
|
let localip = line[3];
|
|
1685
1746
|
let localport = '';
|
|
1686
|
-
|
|
1747
|
+
const localaddress = line[3].split('.');
|
|
1687
1748
|
if (localaddress.length > 1) {
|
|
1688
1749
|
localport = localaddress[localaddress.length - 1];
|
|
1689
1750
|
localaddress.pop();
|
|
@@ -1691,14 +1752,14 @@ function networkConnections(callback) {
|
|
|
1691
1752
|
}
|
|
1692
1753
|
let peerip = line[4];
|
|
1693
1754
|
let peerport = '';
|
|
1694
|
-
|
|
1755
|
+
const peeraddress = line[4].split('.');
|
|
1695
1756
|
if (peeraddress.length > 1) {
|
|
1696
1757
|
peerport = peeraddress[peeraddress.length - 1];
|
|
1697
1758
|
peeraddress.pop();
|
|
1698
1759
|
peerip = peeraddress.join('.');
|
|
1699
1760
|
}
|
|
1700
1761
|
const hasState = states.indexOf(line[5]) >= 0;
|
|
1701
|
-
|
|
1762
|
+
const connstate = hasState ? line[5] : 'UNKNOWN';
|
|
1702
1763
|
let pidField = '';
|
|
1703
1764
|
if (line[line.length - 9].indexOf(':') >= 0) {
|
|
1704
1765
|
pidField = line[line.length - 9].split(':')[1];
|
|
@@ -1709,7 +1770,7 @@ function networkConnections(callback) {
|
|
|
1709
1770
|
pidField = pidField.split(':')[1];
|
|
1710
1771
|
}
|
|
1711
1772
|
}
|
|
1712
|
-
|
|
1773
|
+
const pid = parseInt(pidField, 10);
|
|
1713
1774
|
if (connstate) {
|
|
1714
1775
|
result.push({
|
|
1715
1776
|
protocol: line[0],
|
|
@@ -1735,11 +1796,11 @@ function networkConnections(callback) {
|
|
|
1735
1796
|
if (_windows) {
|
|
1736
1797
|
let cmd = 'netstat -nao';
|
|
1737
1798
|
try {
|
|
1738
|
-
exec(cmd, util.execOptsWin,
|
|
1799
|
+
exec(cmd, util.execOptsWin, (error, stdout) => {
|
|
1739
1800
|
if (!error) {
|
|
1740
1801
|
let lines = stdout.toString().split('\r\n');
|
|
1741
1802
|
|
|
1742
|
-
lines.forEach(
|
|
1803
|
+
lines.forEach((line) => {
|
|
1743
1804
|
line = line.trim().replace(/ +/g, ' ').split(' ');
|
|
1744
1805
|
if (line.length >= 4) {
|
|
1745
1806
|
let localip = line[1];
|
|
@@ -1821,7 +1882,7 @@ function networkConnections(callback) {
|
|
|
1821
1882
|
resolve(result);
|
|
1822
1883
|
}
|
|
1823
1884
|
});
|
|
1824
|
-
} catch
|
|
1885
|
+
} catch {
|
|
1825
1886
|
if (callback) {
|
|
1826
1887
|
callback(result);
|
|
1827
1888
|
}
|
|
@@ -1841,7 +1902,7 @@ function networkGatewayDefault(callback) {
|
|
|
1841
1902
|
if (_linux || _freebsd || _openbsd || _netbsd) {
|
|
1842
1903
|
let cmd = 'ip route get 1';
|
|
1843
1904
|
try {
|
|
1844
|
-
exec(cmd, { maxBuffer: 1024 *
|
|
1905
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1845
1906
|
if (!error) {
|
|
1846
1907
|
let lines = stdout.toString().split('\n');
|
|
1847
1908
|
const line = lines && lines[0] ? lines[0] : '';
|
|
@@ -1861,7 +1922,7 @@ function networkGatewayDefault(callback) {
|
|
|
1861
1922
|
resolve(result);
|
|
1862
1923
|
}
|
|
1863
1924
|
});
|
|
1864
|
-
} catch
|
|
1925
|
+
} catch {
|
|
1865
1926
|
if (callback) {
|
|
1866
1927
|
callback(result);
|
|
1867
1928
|
}
|
|
@@ -1871,7 +1932,7 @@ function networkGatewayDefault(callback) {
|
|
|
1871
1932
|
if (_darwin) {
|
|
1872
1933
|
let cmd = 'route -n get default';
|
|
1873
1934
|
try {
|
|
1874
|
-
exec(cmd, { maxBuffer: 1024 *
|
|
1935
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1875
1936
|
if (!error) {
|
|
1876
1937
|
const lines = stdout
|
|
1877
1938
|
.toString()
|
|
@@ -1881,7 +1942,7 @@ function networkGatewayDefault(callback) {
|
|
|
1881
1942
|
}
|
|
1882
1943
|
if (!result) {
|
|
1883
1944
|
cmd = "netstat -rn | awk '/default/ {print $2}'";
|
|
1884
|
-
exec(cmd, { maxBuffer: 1024 *
|
|
1945
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1885
1946
|
const lines = stdout
|
|
1886
1947
|
.toString()
|
|
1887
1948
|
.split('\n')
|
|
@@ -1901,7 +1962,7 @@ function networkGatewayDefault(callback) {
|
|
|
1901
1962
|
resolve(result);
|
|
1902
1963
|
}
|
|
1903
1964
|
});
|
|
1904
|
-
} catch
|
|
1965
|
+
} catch {
|
|
1905
1966
|
if (callback) {
|
|
1906
1967
|
callback(result);
|
|
1907
1968
|
}
|
|
@@ -1910,7 +1971,7 @@ function networkGatewayDefault(callback) {
|
|
|
1910
1971
|
}
|
|
1911
1972
|
if (_windows) {
|
|
1912
1973
|
try {
|
|
1913
|
-
exec('netstat -r', util.execOptsWin,
|
|
1974
|
+
exec('netstat -r', util.execOptsWin, (error, stdout) => {
|
|
1914
1975
|
const lines = stdout.toString().split(os.EOL);
|
|
1915
1976
|
lines.forEach((line) => {
|
|
1916
1977
|
line = line.replace(/\s+/g, ' ').trim();
|
|
@@ -1953,7 +2014,7 @@ function networkGatewayDefault(callback) {
|
|
|
1953
2014
|
resolve(result);
|
|
1954
2015
|
}
|
|
1955
2016
|
});
|
|
1956
|
-
} catch
|
|
2017
|
+
} catch {
|
|
1957
2018
|
if (callback) {
|
|
1958
2019
|
callback(result);
|
|
1959
2020
|
}
|