minor fixes

This commit is contained in:
Sebastian Hildebrandt 2024-12-25 15:30:42 +01:00
parent e24054f645
commit fe8f5936cb
2 changed files with 34 additions and 25 deletions

View File

@ -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;

View File

@ -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 = '';
}