getMacAddresses() fix added try catch
This commit is contained in:
parent
d8fc1520ec
commit
3d61fe987c
@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 4.23.8 | 2020-04-26 | `getMacAddresses()` fix added try catch |
|
||||
| 4.23.7 | 2020-04-26 | `getCpuCurrentSpeedSync()` workarround fix |
|
||||
| 4.23.6 | 2020-04-25 | `networkGatewayDefault()` bug fix no interfaces |
|
||||
| 4.23.5 | 2020-04-20 | updated docs |
|
||||
|
||||
@ -83,6 +83,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">4.23.8</th>
|
||||
<td>2020-04-2&</td>
|
||||
<td><span class="code">getMacAddresses()</span> fix added try catch</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">4.23.7</th>
|
||||
<td>2020-04-2&</td>
|
||||
|
||||
@ -168,7 +168,7 @@
|
||||
<img class="logo" src="assets/logo.png">
|
||||
<div class="title">systeminformation</div>
|
||||
<div class="subtitle"><span id="typed"></span></div>
|
||||
<div class="version">Current Version: <span id="version">4.23.7</span></div>
|
||||
<div class="version">Current Version: <span id="version">4.23.8</span></div>
|
||||
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
|
||||
</div>
|
||||
<div class="down">
|
||||
|
||||
102
lib/network.js
102
lib/network.js
@ -64,10 +64,10 @@ function getDefaultNetworkInterface() {
|
||||
try {
|
||||
if (_windows) {
|
||||
// https://www.inetdaemon.com/tutorials/internet/ip/routing/default_route.shtml
|
||||
let defaultIp = '';
|
||||
const cmd = 'netstat -r';
|
||||
const result = execSync(cmd);
|
||||
const lines = result.toString().split(os.EOL);
|
||||
let defaultIp = '';
|
||||
lines.forEach(line => {
|
||||
line = line.replace(/\s+/g, ' ').trim();
|
||||
if (line.indexOf('0.0.0.0 0.0.0.0') > -1 && !(/[a-zA-Z]/.test(line))) {
|
||||
@ -126,46 +126,54 @@ function getMacAddresses() {
|
||||
pathToIp = '';
|
||||
}
|
||||
}
|
||||
const cmd = 'export LC_ALL=C; ' + ((pathToIp) ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL';
|
||||
let res = execSync(cmd);
|
||||
const lines = res.toString().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i] && lines[i][0] !== ' ') {
|
||||
if (pathToIp) {
|
||||
let nextline = lines[i + 1].trim().split(' ');
|
||||
if (nextline[0] === 'link/ether') {
|
||||
iface = lines[i].split(' ')[1];
|
||||
iface = iface.slice(0, iface.length - 1);
|
||||
mac = nextline[1];
|
||||
try {
|
||||
const cmd = 'export LC_ALL=C; ' + ((pathToIp) ? pathToIp + ' link show up' : '/sbin/ifconfig') + '; unset LC_ALL';
|
||||
let res = execSync(cmd);
|
||||
const lines = res.toString().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i] && lines[i][0] !== ' ') {
|
||||
if (pathToIp) {
|
||||
let nextline = lines[i + 1].trim().split(' ');
|
||||
if (nextline[0] === 'link/ether') {
|
||||
iface = lines[i].split(' ')[1];
|
||||
iface = iface.slice(0, iface.length - 1);
|
||||
mac = nextline[1];
|
||||
}
|
||||
} else {
|
||||
iface = lines[i].split(' ')[0];
|
||||
mac = lines[i].split('HWaddr ')[1];
|
||||
}
|
||||
} else {
|
||||
iface = lines[i].split(' ')[0];
|
||||
mac = lines[i].split('HWaddr ')[1];
|
||||
}
|
||||
|
||||
if (iface && mac) {
|
||||
result[iface] = mac.trim();
|
||||
iface = '';
|
||||
mac = '';
|
||||
if (iface && mac) {
|
||||
result[iface] = mac.trim();
|
||||
iface = '';
|
||||
mac = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (_darwin) {
|
||||
const cmd = '/sbin/ifconfig';
|
||||
let res = execSync(cmd);
|
||||
const lines = res.toString().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i] && lines[i][0] !== '\t' && lines[i].indexOf(':') > 0) {
|
||||
iface = lines[i].split(':')[0];
|
||||
} else if (lines[i].indexOf('\tether ') === 0) {
|
||||
mac = lines[i].split('\tether ')[1];
|
||||
if (iface && mac) {
|
||||
result[iface] = mac.trim();
|
||||
iface = '';
|
||||
mac = '';
|
||||
try {
|
||||
const cmd = '/sbin/ifconfig';
|
||||
let res = execSync(cmd);
|
||||
const lines = res.toString().split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (lines[i] && lines[i][0] !== '\t' && lines[i].indexOf(':') > 0) {
|
||||
iface = lines[i].split(':')[0];
|
||||
} else if (lines[i].indexOf('\tether ') === 0) {
|
||||
mac = lines[i].split('\tether ')[1];
|
||||
if (iface && mac) {
|
||||
result[iface] = mac.trim();
|
||||
iface = '';
|
||||
mac = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -491,21 +499,25 @@ function getLinuxIfaceConnectionName(interfaceName) {
|
||||
|
||||
function checkLinuxDCHPInterfaces(file) {
|
||||
let result = [];
|
||||
let cmd = `cat ${file} 2> /dev/null | grep 'iface\\|source'`;
|
||||
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
|
||||
try {
|
||||
let cmd = `cat ${file} 2> /dev/null | grep 'iface\\|source'`;
|
||||
const lines = execSync(cmd, { maxBuffer: 1024 * 20000 }).toString().split('\n');
|
||||
|
||||
lines.forEach(line => {
|
||||
const parts = line.replace(/\s+/g, ' ').trim().split(' ');
|
||||
if (parts.length >= 4) {
|
||||
if (line.toLowerCase().indexOf(' inet ') >= 0 && line.toLowerCase().indexOf('dhcp') >= 0) {
|
||||
result.push(parts[1]);
|
||||
lines.forEach(line => {
|
||||
const parts = line.replace(/\s+/g, ' ').trim().split(' ');
|
||||
if (parts.length >= 4) {
|
||||
if (line.toLowerCase().indexOf(' inet ') >= 0 && line.toLowerCase().indexOf('dhcp') >= 0) {
|
||||
result.push(parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line.toLowerCase().includes('source')) {
|
||||
let file = line.split(' ')[1];
|
||||
result = result.concat(checkLinuxDCHPInterfaces(file));
|
||||
}
|
||||
});
|
||||
if (line.toLowerCase().includes('source')) {
|
||||
let file = line.split(' ')[1];
|
||||
result = result.concat(checkLinuxDCHPInterfaces(file));
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user