diff --git a/lib/network.js b/lib/network.js index 69d23cc..17be947 100644 --- a/lib/network.js +++ b/lib/network.js @@ -212,33 +212,42 @@ exports.networkInterfaceDefault = networkInterfaceDefault; function parseLinesWindowsNics(sections, nconfigsections) { let nics = []; for (let i in sections) { - if ({}.hasOwnProperty.call(sections, i)) { + try { + if ({}.hasOwnProperty.call(sections, i)) { - if (sections[i].trim() !== '') { + if (sections[i].trim() !== '') { - let lines = sections[i].trim().split('\r\n'); - let linesNicConfig = nconfigsections && nconfigsections[i] ? nconfigsections[i].trim().split('\r\n') : []; - let netEnabled = util.getValue(lines, 'NetEnabled', ':'); - let adapterType = util.getValue(lines, 'AdapterTypeID', ':') === '9' ? 'wireless' : 'wired'; - let ifacename = util.getValue(lines, 'Name', ':').replace(/\]/g, ')').replace(/\[/g, '('); - let iface = util.getValue(lines, 'NetConnectionID', ':').replace(/\]/g, ')').replace(/\[/g, '('); - if (ifacename.toLowerCase().indexOf('wi-fi') >= 0 || ifacename.toLowerCase().indexOf('wireless') >= 0) { - adapterType = 'wireless'; - } - if (netEnabled !== '') { - const speed = parseInt(util.getValue(lines, 'speed', ':').trim(), 10) / 1000000; - nics.push({ - mac: util.getValue(lines, 'MACAddress', ':').toLowerCase(), - dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', ':').toLowerCase() === 'true', - name: ifacename, - iface, - netEnabled: netEnabled === 'TRUE', - speed: isNaN(speed) ? null : speed, - operstate: util.getValue(lines, 'NetConnectionStatus', ':') === '2' ? 'up' : 'down', - type: adapterType - }); + let lines = sections[i].trim().split('\r\n'); + let linesNicConfig = null; + try { + linesNicConfig = nconfigsections && nconfigsections[i] ? nconfigsections[i].trim().split('\r\n') : []; + } catch (e) { + util.noop(); + } + let netEnabled = util.getValue(lines, 'NetEnabled', ':'); + let adapterType = util.getValue(lines, 'AdapterTypeID', ':') === '9' ? 'wireless' : 'wired'; + let ifacename = util.getValue(lines, 'Name', ':').replace(/\]/g, ')').replace(/\[/g, '('); + let iface = util.getValue(lines, 'NetConnectionID', ':').replace(/\]/g, ')').replace(/\[/g, '('); + if (ifacename.toLowerCase().indexOf('wi-fi') >= 0 || ifacename.toLowerCase().indexOf('wireless') >= 0) { + adapterType = 'wireless'; + } + if (netEnabled !== '') { + const speed = parseInt(util.getValue(lines, 'speed', ':').trim(), 10) / 1000000; + nics.push({ + mac: util.getValue(lines, 'MACAddress', ':').toLowerCase(), + dhcp: util.getValue(linesNicConfig, 'dhcpEnabled', ':').toLowerCase() === 'true', + name: ifacename, + iface, + netEnabled: netEnabled === 'TRUE', + speed: isNaN(speed) ? null : speed, + operstate: util.getValue(lines, 'NetConnectionStatus', ':') === '2' ? 'up' : 'down', + type: adapterType + }); + } } } + } catch (e) { + util.noop(); } } return nics; diff --git a/lib/util.js b/lib/util.js index e595613..c76bf05 100644 --- a/lib/util.js +++ b/lib/util.js @@ -579,7 +579,7 @@ function getCodepage() { if (_linux || _darwin || _freebsd || _openbsd || _netbsd) { if (!codepage) { try { - const stdout = execSync('echo $LANG', util.execOptsLinux); + const stdout = execSync('echo $LANG', execOptsLinux); const lines = stdout.toString().split('\r\n'); const parts = lines[0].split('.'); codepage = parts.length > 1 ? parts[1].trim() : ''; @@ -1156,7 +1156,7 @@ function linuxVersion() { let result = ''; if (_linux) { try { - result = execSync('uname -v', util.execOptsLinux).toString(); + result = execSync('uname -v', execOptsLinux).toString(); } catch (e) { result = ''; }