networkInterfaces() added subnet mask ip4 and ip6

This commit is contained in:
Sebastian Hildebrandt 2020-05-01 20:21:23 +02:00
parent 0495740a32
commit 4c6b6a257a
9 changed files with 60 additions and 3 deletions

View File

@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page.
| Version | Date | Comment |
| -------------- | -------------- | -------- |
| 4.24.0 | 2020-05-01 | `networkInterfaces()` added subnet mask ip4 and ip6 |
| 4.23.10 | 2020-05-01 | `cpuTemperature()` optimized parsing linux |
| 4.23.9 | 2020-04-29 | `currentLoad()` workarround for no os.cpus info |
| 4.23.8 | 2020-04-26 | `getMacAddresses()` fix added try catch |

View File

@ -87,13 +87,13 @@ si.cpu()
(last 7 major and minor version releases)
- Version 4.24.0: `networkInterfaces()` added subnet mask ip4 and ip6
- Version 4.23.0: `versions()` added param to specify which program/lib versions to detect
- Version 4.22.0: `services()` added pids (windows)
- Version 4.21.0: added npx copmpatibility
- Version 4.20.0: `battery()` added designcapacity, voltage, unit
- Version 4.19.0: `osInfo()` added uefi (OS uses UEFI during startup)
- Version 4.18.0: `networkInterfaces()` added dhcp for mac os, added dhcp linux fallback
- Version 4.17.0: `networkInterfaces()` added dhcp, dnsSuffix, ieee8021xAuth, ieee8021xState
- ...
You can find all changes here: [detailed changelog][changelog-url]
@ -431,7 +431,9 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| | [0].iface | X | X | X | X | X | interface |
| | [0].ifaceName | X | X | X | X | X | interface name (differs on Windows) |
| | [0].ip4 | X | X | X | X | X | ip4 address |
| | [0].ip4subnet | X | X | X | X | X | ip4 subnet mask |
| | [0].ip6 | X | X | X | X | X | ip6 address |
| | [0].ip6subnet | X | X | X | X | X | ip6 subnet mask |
| | [0].mac | X | X | X | X | X | MAC address |
| | [0].internal | X | X | X | X | X | true if internal interface |
| | [0].virtual | X | X | X | X | X | true if virtual interface |

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.24.0</th>
<td>2020-05-01</td>
<td><span class="code">networkInterfaces()</span> added netmask ip4 and ip6</td>
</tr>
<tr>
<th scope="row">4.23.10</th>
<td>2020-05-01</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.23.10</span></div>
<div class="version">Current Version: <span id="version">4.24.0</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">

View File

@ -105,6 +105,16 @@
<td>X</td>
<td>ip4 address</td>
</tr>
<tr>
<td></td>
<td>[0].ip4subnet</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>ip4 subnet mask</td>
</tr>
<tr>
<td></td>
<td>[0].ip6</td>
@ -115,6 +125,16 @@
<td>X</td>
<td>ip6 address</td>
</tr>
<tr>
<td></td>
<td>[0].ip6subnet</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>X</td>
<td>ip6 subnet mask</td>
</tr>
<tr>
<td></td>
<td>[0].mac</td>
@ -257,7 +277,9 @@ si.networkInterfaces().then(data => console.log(data));</code></pre class="examp
iface: 'lo0',
ifaceName: 'lo0',
ip4: '127.0.0.1',
ip4subnet: '255.0.0.0',
ip6: '::1',
ip6subnet: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
mac: '',
internal: true,
virtual: false,
@ -276,7 +298,9 @@ si.networkInterfaces().then(data => console.log(data));</code></pre class="examp
iface: 'en0',
ifaceName: 'en0',
ip4: '192.168.0.27',
ip4subnet: '255.255.255.0',
ip6: 'fe80::134a:1e43:abc5:d413',
ip6subnet: 'ffff:ffff:ffff:ffff::',
mac: 'xx:xx:xx:xx:xx:xx',
internal: false,
virtual: false,

View File

@ -779,6 +779,9 @@ function cpuTemperature(callback) {
result.max = (maxtmp > result.main) ? maxtmp : result.main;
}
if (result.main !== -1) {
if (result.max === -1) {
result.max = result.main;
}
if (callback) { callback(result); }
resolve(result);
}

2
lib/index.d.ts vendored
View File

@ -314,7 +314,9 @@ export namespace Systeminformation {
iface: string;
ifaceName: string;
ip4: string;
ip4subnet: string;
ip6: string;
ip6subnet: string;
mac: string;
internal: boolean;
virtual: boolean;

View File

@ -694,13 +694,27 @@ function networkInterfaces(callback) {
if (_darwin || _freebsd || _openbsd || _netbsd) {
nics = getDarwinNics();
nics.forEach(nic => {
if ({}.hasOwnProperty.call(ifaces, nic.iface)) {
ifaces[nic.iface].forEach(function (details) {
if (details.family === 'IPv4') {
nic.ip4subnet = details.netmask;
}
if (details.family === 'IPv6') {
nic.ip6subnet = details.netmask;
}
});
}
result.push({
iface: nic.iface,
ifaceName: nic.iface,
ip4: nic.ip4,
ip4subnet: nic.ip4subnet || '',
ip6: nic.ip6,
ip6subnet: nic.ip6subnet || '',
mac: nic.mac,
internal: nic.internal,
virtual: nic.internal ? false : testVirtualNic(nic.iface, nic.iface, nic.mac),
@ -737,7 +751,9 @@ function networkInterfaces(callback) {
}
for (let dev in ifaces) {
let ip4 = '';
let ip4subnet = '';
let ip6 = '';
let ip6subnet = '';
let mac = '';
let duplex = '';
let mtu = '';
@ -755,10 +771,12 @@ function networkInterfaces(callback) {
ifaces[dev].forEach(function (details) {
if (details.family === 'IPv4') {
ip4 = details.address;
ip4subnet = details.netmask;
}
if (details.family === 'IPv6') {
if (!ip6 || ip6.match(/^fe80::/i)) {
ip6 = details.address;
ip6subnet = details.netmask;
}
}
mac = details.mac;
@ -852,7 +870,9 @@ function networkInterfaces(callback) {
iface: dev,
ifaceName,
ip4,
ip4subnet,
ip6,
ip6subnet,
mac,
internal,
virtual,

View File

@ -4,7 +4,7 @@
"description": "Simple system and OS information library",
"license": "MIT",
"author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",
"homepage": "https://github.com/sebhildebrandt/systeminformation",
"homepage": "https://systeminformation.io",
"main": "./lib/index.js",
"bin": "./lib/cli.js",
"types": "./lib/index.d.ts",