systeminformation 5.28.1 → 5.28.3
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 +17 -11
- package/lib/index.js +35 -30
- package/lib/network.js +68 -58
- package/lib/osinfo.js +128 -144
- package/lib/processes.js +111 -120
- 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;
|
|
@@ -562,7 +562,7 @@ 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
|
});
|
|
@@ -574,7 +574,7 @@ 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');
|
|
@@ -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;
|
|
@@ -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 = [];
|
|
@@ -1066,7 +1066,7 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
1066
1066
|
_ifaces = JSON.parse(JSON.stringify(ifaces));
|
|
1067
1067
|
const defaultInterface = getDefaultNetworkInterface();
|
|
1068
1068
|
|
|
1069
|
-
getWindowsNics().then(
|
|
1069
|
+
getWindowsNics().then((nics) => {
|
|
1070
1070
|
nics.forEach((nic) => {
|
|
1071
1071
|
let found = false;
|
|
1072
1072
|
Object.keys(ifaces).forEach((key) => {
|
|
@@ -1114,7 +1114,7 @@ function networkInterfaces(callback, rescan, defaultString) {
|
|
|
1114
1114
|
|
|
1115
1115
|
if ({}.hasOwnProperty.call(ifaces, dev)) {
|
|
1116
1116
|
let ifaceName = dev;
|
|
1117
|
-
ifaces[dev].forEach(
|
|
1117
|
+
ifaces[dev].forEach((details) => {
|
|
1118
1118
|
if (details.family === 'IPv4' || details.family === 4) {
|
|
1119
1119
|
ip4 = details.address;
|
|
1120
1120
|
ip4subnet = details.netmask;
|
|
@@ -1219,7 +1219,7 @@ exports.networkInterfaces = networkInterfaces;
|
|
|
1219
1219
|
// NET - Speed
|
|
1220
1220
|
|
|
1221
1221
|
function calcNetworkSpeed(iface, rx_bytes, tx_bytes, operstate, rx_dropped, rx_errors, tx_dropped, tx_errors) {
|
|
1222
|
-
|
|
1222
|
+
const result = {
|
|
1223
1223
|
iface,
|
|
1224
1224
|
operstate,
|
|
1225
1225
|
rx_bytes,
|
|
@@ -1420,7 +1420,7 @@ function networkStatsSingle(iface) {
|
|
|
1420
1420
|
'cat /sys/class/net/' +
|
|
1421
1421
|
ifaceSanitized +
|
|
1422
1422
|
'/statistics/tx_errors; ';
|
|
1423
|
-
exec(cmd,
|
|
1423
|
+
exec(cmd, (error, stdout) => {
|
|
1424
1424
|
if (!error) {
|
|
1425
1425
|
lines = stdout.toString().split('\n');
|
|
1426
1426
|
operstate = lines[0].trim();
|
|
@@ -1441,7 +1441,7 @@ function networkStatsSingle(iface) {
|
|
|
1441
1441
|
}
|
|
1442
1442
|
if (_freebsd || _openbsd || _netbsd) {
|
|
1443
1443
|
cmd = 'netstat -ibndI ' + ifaceSanitized; // lgtm [js/shell-command-constructed-from-input]
|
|
1444
|
-
exec(cmd,
|
|
1444
|
+
exec(cmd, (error, stdout) => {
|
|
1445
1445
|
if (!error) {
|
|
1446
1446
|
lines = stdout.toString().split('\n');
|
|
1447
1447
|
for (let i = 1; i < lines.length; i++) {
|
|
@@ -1471,7 +1471,7 @@ function networkStatsSingle(iface) {
|
|
|
1471
1471
|
}
|
|
1472
1472
|
if (_darwin) {
|
|
1473
1473
|
cmd = 'ifconfig ' + ifaceSanitized + ' | grep "status"'; // lgtm [js/shell-command-constructed-from-input]
|
|
1474
|
-
exec(cmd,
|
|
1474
|
+
exec(cmd, (error, stdout) => {
|
|
1475
1475
|
result.operstate = (stdout.toString().split(':')[1] || '').trim();
|
|
1476
1476
|
result.operstate = (result.operstate || '').toLowerCase();
|
|
1477
1477
|
result.operstate = result.operstate === 'active' ? 'up' : result.operstate === 'inactive' ? 'down' : 'unknown';
|
|
@@ -1602,15 +1602,15 @@ function networkConnections(callback) {
|
|
|
1602
1602
|
cmd =
|
|
1603
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';
|
|
1604
1604
|
}
|
|
1605
|
-
exec(cmd, { maxBuffer: 1024 * 102400 },
|
|
1605
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1606
1606
|
let lines = stdout.toString().split('\n');
|
|
1607
1607
|
if (!error && (lines.length > 1 || lines[0] !== '')) {
|
|
1608
|
-
lines.forEach(
|
|
1608
|
+
lines.forEach((line) => {
|
|
1609
1609
|
line = line.replace(/ +/g, ' ').split(' ');
|
|
1610
1610
|
if (line.length >= 7) {
|
|
1611
1611
|
let localip = line[3];
|
|
1612
1612
|
let localport = '';
|
|
1613
|
-
|
|
1613
|
+
const localaddress = line[3].split(':');
|
|
1614
1614
|
if (localaddress.length > 1) {
|
|
1615
1615
|
localport = localaddress[localaddress.length - 1];
|
|
1616
1616
|
localaddress.pop();
|
|
@@ -1618,14 +1618,14 @@ function networkConnections(callback) {
|
|
|
1618
1618
|
}
|
|
1619
1619
|
let peerip = line[4];
|
|
1620
1620
|
let peerport = '';
|
|
1621
|
-
|
|
1621
|
+
const peeraddress = line[4].split(':');
|
|
1622
1622
|
if (peeraddress.length > 1) {
|
|
1623
1623
|
peerport = peeraddress[peeraddress.length - 1];
|
|
1624
1624
|
peeraddress.pop();
|
|
1625
1625
|
peerip = peeraddress.join(':');
|
|
1626
1626
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1627
|
+
const connstate = line[5];
|
|
1628
|
+
const proc = line[6].split('/');
|
|
1629
1629
|
|
|
1630
1630
|
if (connstate) {
|
|
1631
1631
|
result.push({
|
|
@@ -1647,15 +1647,15 @@ function networkConnections(callback) {
|
|
|
1647
1647
|
resolve(result);
|
|
1648
1648
|
} else {
|
|
1649
1649
|
cmd = 'ss -tunap | grep "ESTAB\\|SYN-SENT\\|SYN-RECV\\|FIN-WAIT1\\|FIN-WAIT2\\|TIME-WAIT\\|CLOSE\\|CLOSE-WAIT\\|LAST-ACK\\|LISTEN\\|CLOSING"';
|
|
1650
|
-
exec(cmd, { maxBuffer: 1024 * 102400 },
|
|
1650
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1651
1651
|
if (!error) {
|
|
1652
|
-
|
|
1653
|
-
lines.forEach(
|
|
1652
|
+
const lines = stdout.toString().split('\n');
|
|
1653
|
+
lines.forEach((line) => {
|
|
1654
1654
|
line = line.replace(/ +/g, ' ').split(' ');
|
|
1655
1655
|
if (line.length >= 6) {
|
|
1656
1656
|
let localip = line[4];
|
|
1657
1657
|
let localport = '';
|
|
1658
|
-
|
|
1658
|
+
const localaddress = line[4].split(':');
|
|
1659
1659
|
if (localaddress.length > 1) {
|
|
1660
1660
|
localport = localaddress[localaddress.length - 1];
|
|
1661
1661
|
localaddress.pop();
|
|
@@ -1663,7 +1663,7 @@ function networkConnections(callback) {
|
|
|
1663
1663
|
}
|
|
1664
1664
|
let peerip = line[5];
|
|
1665
1665
|
let peerport = '';
|
|
1666
|
-
|
|
1666
|
+
const peeraddress = line[5].split(':');
|
|
1667
1667
|
if (peeraddress.length > 1) {
|
|
1668
1668
|
peerport = peeraddress[peeraddress.length - 1];
|
|
1669
1669
|
peeraddress.pop();
|
|
@@ -1679,12 +1679,22 @@ function networkConnections(callback) {
|
|
|
1679
1679
|
let pid = null;
|
|
1680
1680
|
let process = '';
|
|
1681
1681
|
if (line.length >= 7 && line[6].indexOf('users:') > -1) {
|
|
1682
|
-
|
|
1682
|
+
const proc = line[6].replace('users:(("', '').replace(/"/g, '').replace('pid=', '').split(',');
|
|
1683
1683
|
if (proc.length > 2) {
|
|
1684
|
-
process = proc[0]
|
|
1685
|
-
|
|
1684
|
+
process = proc[0];
|
|
1685
|
+
const pidValue = parseInt(proc[1], 10);
|
|
1686
|
+
if (pidValue > 0) {
|
|
1687
|
+
pid = pidValue;
|
|
1688
|
+
}
|
|
1686
1689
|
}
|
|
1687
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
|
+
// }
|
|
1688
1698
|
if (connstate) {
|
|
1689
1699
|
result.push({
|
|
1690
1700
|
protocol: line[0],
|
|
@@ -1709,16 +1719,16 @@ function networkConnections(callback) {
|
|
|
1709
1719
|
});
|
|
1710
1720
|
}
|
|
1711
1721
|
if (_darwin) {
|
|
1712
|
-
|
|
1722
|
+
const cmd = 'netstat -natvln | head -n2; netstat -natvln | grep "tcp4\\|tcp6\\|udp4\\|udp6"';
|
|
1713
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('|');
|
|
1714
|
-
exec(cmd, { maxBuffer: 1024 * 102400 },
|
|
1724
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1715
1725
|
if (!error) {
|
|
1716
|
-
exec('ps -axo pid,command', { maxBuffer: 1024 * 102400 },
|
|
1726
|
+
exec('ps -axo pid,command', { maxBuffer: 1024 * 102400 }, (err2, stdout2) => {
|
|
1717
1727
|
let processes = stdout2.toString().split('\n');
|
|
1718
1728
|
processes = processes.map((line) => {
|
|
1719
1729
|
return line.trim().replace(/ +/g, ' ');
|
|
1720
1730
|
});
|
|
1721
|
-
|
|
1731
|
+
const lines = stdout.toString().split('\n');
|
|
1722
1732
|
lines.shift();
|
|
1723
1733
|
let pidPos = 8;
|
|
1724
1734
|
if (lines.length > 1 && lines[0].indexOf('pid') > 0) {
|
|
@@ -1729,12 +1739,12 @@ function networkConnections(callback) {
|
|
|
1729
1739
|
.split(' ');
|
|
1730
1740
|
pidPos = header.indexOf('pid');
|
|
1731
1741
|
}
|
|
1732
|
-
lines.forEach(
|
|
1742
|
+
lines.forEach((line) => {
|
|
1733
1743
|
line = line.replace(/ +/g, ' ').split(' ');
|
|
1734
1744
|
if (line.length >= 8) {
|
|
1735
1745
|
let localip = line[3];
|
|
1736
1746
|
let localport = '';
|
|
1737
|
-
|
|
1747
|
+
const localaddress = line[3].split('.');
|
|
1738
1748
|
if (localaddress.length > 1) {
|
|
1739
1749
|
localport = localaddress[localaddress.length - 1];
|
|
1740
1750
|
localaddress.pop();
|
|
@@ -1742,14 +1752,14 @@ function networkConnections(callback) {
|
|
|
1742
1752
|
}
|
|
1743
1753
|
let peerip = line[4];
|
|
1744
1754
|
let peerport = '';
|
|
1745
|
-
|
|
1755
|
+
const peeraddress = line[4].split('.');
|
|
1746
1756
|
if (peeraddress.length > 1) {
|
|
1747
1757
|
peerport = peeraddress[peeraddress.length - 1];
|
|
1748
1758
|
peeraddress.pop();
|
|
1749
1759
|
peerip = peeraddress.join('.');
|
|
1750
1760
|
}
|
|
1751
1761
|
const hasState = states.indexOf(line[5]) >= 0;
|
|
1752
|
-
|
|
1762
|
+
const connstate = hasState ? line[5] : 'UNKNOWN';
|
|
1753
1763
|
let pidField = '';
|
|
1754
1764
|
if (line[line.length - 9].indexOf(':') >= 0) {
|
|
1755
1765
|
pidField = line[line.length - 9].split(':')[1];
|
|
@@ -1760,7 +1770,7 @@ function networkConnections(callback) {
|
|
|
1760
1770
|
pidField = pidField.split(':')[1];
|
|
1761
1771
|
}
|
|
1762
1772
|
}
|
|
1763
|
-
|
|
1773
|
+
const pid = parseInt(pidField, 10);
|
|
1764
1774
|
if (connstate) {
|
|
1765
1775
|
result.push({
|
|
1766
1776
|
protocol: line[0],
|
|
@@ -1786,11 +1796,11 @@ function networkConnections(callback) {
|
|
|
1786
1796
|
if (_windows) {
|
|
1787
1797
|
let cmd = 'netstat -nao';
|
|
1788
1798
|
try {
|
|
1789
|
-
exec(cmd, util.execOptsWin,
|
|
1799
|
+
exec(cmd, util.execOptsWin, (error, stdout) => {
|
|
1790
1800
|
if (!error) {
|
|
1791
1801
|
let lines = stdout.toString().split('\r\n');
|
|
1792
1802
|
|
|
1793
|
-
lines.forEach(
|
|
1803
|
+
lines.forEach((line) => {
|
|
1794
1804
|
line = line.trim().replace(/ +/g, ' ').split(' ');
|
|
1795
1805
|
if (line.length >= 4) {
|
|
1796
1806
|
let localip = line[1];
|
|
@@ -1892,7 +1902,7 @@ function networkGatewayDefault(callback) {
|
|
|
1892
1902
|
if (_linux || _freebsd || _openbsd || _netbsd) {
|
|
1893
1903
|
let cmd = 'ip route get 1';
|
|
1894
1904
|
try {
|
|
1895
|
-
exec(cmd, { maxBuffer: 1024 * 102400 },
|
|
1905
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1896
1906
|
if (!error) {
|
|
1897
1907
|
let lines = stdout.toString().split('\n');
|
|
1898
1908
|
const line = lines && lines[0] ? lines[0] : '';
|
|
@@ -1922,7 +1932,7 @@ function networkGatewayDefault(callback) {
|
|
|
1922
1932
|
if (_darwin) {
|
|
1923
1933
|
let cmd = 'route -n get default';
|
|
1924
1934
|
try {
|
|
1925
|
-
exec(cmd, { maxBuffer: 1024 * 102400 },
|
|
1935
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1926
1936
|
if (!error) {
|
|
1927
1937
|
const lines = stdout
|
|
1928
1938
|
.toString()
|
|
@@ -1932,7 +1942,7 @@ function networkGatewayDefault(callback) {
|
|
|
1932
1942
|
}
|
|
1933
1943
|
if (!result) {
|
|
1934
1944
|
cmd = "netstat -rn | awk '/default/ {print $2}'";
|
|
1935
|
-
exec(cmd, { maxBuffer: 1024 * 102400 },
|
|
1945
|
+
exec(cmd, { maxBuffer: 1024 * 102400 }, (error, stdout) => {
|
|
1936
1946
|
const lines = stdout
|
|
1937
1947
|
.toString()
|
|
1938
1948
|
.split('\n')
|
|
@@ -1961,7 +1971,7 @@ function networkGatewayDefault(callback) {
|
|
|
1961
1971
|
}
|
|
1962
1972
|
if (_windows) {
|
|
1963
1973
|
try {
|
|
1964
|
-
exec('netstat -r', util.execOptsWin,
|
|
1974
|
+
exec('netstat -r', util.execOptsWin, (error, stdout) => {
|
|
1965
1975
|
const lines = stdout.toString().split(os.EOL);
|
|
1966
1976
|
lines.forEach((line) => {
|
|
1967
1977
|
line = line.replace(/\s+/g, ' ').trim();
|