network() fixed DHCP linux, diskLayout() fixed linux

This commit is contained in:
Sebastian Hildebrandt 2020-03-08 16:16:52 +01:00
parent 297371fb06
commit 1464b4d134
6 changed files with 46 additions and 29 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 4.22.6 | 2020-03-08 | `network()` fixed DHCP linux, `diskLayout()` fixed linux |
| 4.22.5 | 2020-03-04 | `graphics()` fixed vram macOS |
| 4.22.4 | 2020-03-01 | `versions()` added dotnet, typings fix |
| 4.22.3 | 2020-02-20 | `memLayout()` code cleanup |

View File

@ -58,7 +58,7 @@
<p><a href="https://nodejs.org/en/" rel="nofollow">Node.js</a> comes with some basic OS information, but I always wanted a little more. So I came up to write this
little library. This library is still work in progress. It is supposed to be used as a backend/server-side library (will definilely not work within a browser). It requires node.js version 4.0 and above.</p>
<p>I was able to test it on several Debian, Raspbian, Ubuntu distributions as well as macOS (Mavericks, Yosemite, El Captain, Sierra, High Sierra) and some Windows 7, Windows 10, FreeBSD, OpenBSD, NetBSD and SunOS machines.
<p>I was able to test it on several Debian, Raspbian, Ubuntu distributions as well as macOS (Mavericks, Yosemite, El Captain, Sierra, High Sierra, Mojave) and some Windows 7, Windows 10, FreeBSD, OpenBSD, NetBSD and SunOS machines.
Not all functions are supported on all operating systems. Have a look at the function reference in the docs to get further details.</p>
<p>If you have comments, suggestions &amp; reports, please feel free to contact me on <a href="https://github.com/sebhildebrandt/systeminformation/issues">github</a>!</p>
<p>I also created a nice little command line tool called <a href="https://github.com/sebhildebrandt/mmon" rel="nofollow">mmon</a> (micro-monitor) for Linux and macOS, also available via <a href="https://github.com/sebhildebrandt/mmon" rel="nofollow">github</a> and <a href="https://npmjs.org/package/mmon" rel="nofollow">npm</a></p>

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.22.6</th>
<td>2020-03-08</td>
<td><span class="code">network()</span> fixed DHCP detection (linux)</td>
</tr>
<tr>
<th scope="row">4.22.5</th>
<td>2020-03-04</td>

View File

@ -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.22.5</span></div>
<div class="version">Current Version: <span id="version">4.22.6</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">
@ -207,7 +207,7 @@
<div class="title">Downloads last month</div>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
<div class="numbers">250</div>
<div class="numbers">251</div>
<div class="title">Dependends</div>
</div>
</div>

View File

@ -745,14 +745,14 @@ function diskLayout(callback) {
try {
const outJSON = JSON.parse(out);
if (outJSON && {}.hasOwnProperty.call(outJSON, 'blockdevices')) {
devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; });
devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && (item.model !== null || (item.mountpoint === null && item.label === null && item.fstype === null)); });
}
} catch (e) {
// fallback to older version of lsblk
const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP 2>/dev/null; unset LC_ALL').toString();
let lines = blkStdoutToObject(out2).split('\n');
const data = parseBlk(lines);
devices = data.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null && item.model !== ''; });
devices = data.filter(item => { return item.group === 'disk' && item.size > 0 && ((item.model !== null && item.model !== '') || (item.mountpoint === '' && item.label === '' && item.fstype === '')); });
}
devices.forEach((device) => {
let mediumType = '';

View File

@ -489,6 +489,26 @@ 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');
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));
}
});
return result;
}
function getLinuxDHCPNics() {
// alternate methods getting interfaces using DHCP
let cmd = 'ip a 2> /dev/null';
@ -501,16 +521,7 @@ function getLinuxDHCPNics() {
util.noop();
}
try {
cmd = 'cat /etc/network/interfaces 2> /dev/null | grep iface';
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]);
}
}
});
result = checkLinuxDCHPInterfaces('/etc/network/interfaces');
} catch (e) {
util.noop();
}
@ -1423,20 +1434,20 @@ function networkGatewayDefault(callback) {
callback(result);
}
resolve(result);
// } else {
// exec('ipconfig', util.execOptsWin, function (error, stdout) {
// let lines = stdout.toString().split('\r\n');
// lines.forEach(function (line) {
// line = line.trim().replace(/\. /g, '');
// line = line.trim().replace(/ +/g, '');
// const parts = line.split(':');
// if ((parts[0].toLowerCase().startsWith('standardgate') || parts[0].toLowerCase().indexOf('gateway') > -1 || parts[0].toLowerCase().indexOf('enlace') > -1) && parts[1]) {
// result = parts[1];
// }
// });
// if (callback) { callback(result); }
// resolve(result);
// });
// } else {
// exec('ipconfig', util.execOptsWin, function (error, stdout) {
// let lines = stdout.toString().split('\r\n');
// lines.forEach(function (line) {
// line = line.trim().replace(/\. /g, '');
// line = line.trim().replace(/ +/g, '');
// const parts = line.split(':');
// if ((parts[0].toLowerCase().startsWith('standardgate') || parts[0].toLowerCase().indexOf('gateway') > -1 || parts[0].toLowerCase().indexOf('enlace') > -1) && parts[1]) {
// result = parts[1];
// }
// });
// if (callback) { callback(result); }
// resolve(result);
// });
}
});
} else {