networkInterfaces() added default property and parameter
This commit is contained in:
parent
fe0d9703a9
commit
b4ae9c3ac0
@ -80,6 +80,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 5.11.0 | 2022-01-26 | `networkInterfaces()` added default property and parameter |
|
||||||
| 5.10.7 | 2022-01-21 | `processes()` reverted PR #560 (windows) |
|
| 5.10.7 | 2022-01-21 | `processes()` reverted PR #560 (windows) |
|
||||||
| 5.10.6 | 2022-01-21 | `usb()` fix `users()` fix tty (windows) |
|
| 5.10.6 | 2022-01-21 | `usb()` fix `users()` fix tty (windows) |
|
||||||
| 5.10.5 | 2022-01-19 | `processes()` fix calculation (windows) |
|
| 5.10.5 | 2022-01-19 | `processes()` fix calculation (windows) |
|
||||||
|
|||||||
@ -101,6 +101,7 @@ si.cpu()
|
|||||||
|
|
||||||
(last 7 major and minor version releases)
|
(last 7 major and minor version releases)
|
||||||
|
|
||||||
|
- Version 5.11.0: `networkInterfaces()` added default property and default parameter
|
||||||
- Version 5.10.0: basic `android` support
|
- Version 5.10.0: basic `android` support
|
||||||
- Version 5.9.0: `graphics()` added properties (macOS)
|
- Version 5.9.0: `graphics()` added properties (macOS)
|
||||||
- Version 5.8.0: `disksIO()` added waitTime, waitPercent (linux)
|
- Version 5.8.0: `disksIO()` added waitTime, waitPercent (linux)
|
||||||
@ -539,9 +540,10 @@ Full function reference with examples can be found at [https://systeminformation
|
|||||||
|
|
||||||
| Function | Result object | Linux | BSD | Mac | Win | Sun | Comments |
|
| Function | Result object | Linux | BSD | Mac | Win | Sun | Comments |
|
||||||
| --------------- | ------------- | ----- | ------- | --- | --- | --- | -------- |
|
| --------------- | ------------- | ----- | ------- | --- | --- | --- | -------- |
|
||||||
| si.networkInterfaces(cb) | [{...}] | X | X | X | X | X | array of network interfaces |
|
| si.networkInterfaces(cb) | [{...}] | X | X | X | X | X | array of network interfaces<br>With the 'default' parameter it returns<br>only the default interface |
|
||||||
| | [0].iface | X | X | X | X | X | interface |
|
| | [0].iface | X | X | X | X | X | interface |
|
||||||
| | [0].ifaceName | X | X | X | X | X | interface name (differs on Windows) |
|
| | [0].ifaceName | X | X | X | X | X | interface name (differs on Windows) |
|
||||||
|
| | [0].default | X | X | X | X | X | true if this is the default interface |
|
||||||
| | [0].ip4 | X | X | X | X | X | ip4 address |
|
| | [0].ip4 | X | X | X | X | X | ip4 address |
|
||||||
| | [0].ip4subnet | X | X | X | X | X | ip4 subnet mask |
|
| | [0].ip4subnet | X | X | X | X | X | ip4 subnet mask |
|
||||||
| | [0].ip6 | X | X | X | X | X | ip6 address |
|
| | [0].ip6 | X | X | X | X | X | ip6 address |
|
||||||
|
|||||||
@ -57,6 +57,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">5.11.0</th>
|
||||||
|
<td>2022-01-26</td>
|
||||||
|
<td><span class="code">networkInterfaces()</span> added default property and parameter</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">5.10.7</th>
|
<th scope="row">5.10.7</th>
|
||||||
<td>2022-01-21</td>
|
<td>2022-01-21</td>
|
||||||
|
|||||||
@ -170,7 +170,7 @@
|
|||||||
<img class="logo" src="assets/logo.png">
|
<img class="logo" src="assets/logo.png">
|
||||||
<div class="title">systeminformation</div>
|
<div class="title">systeminformation</div>
|
||||||
<div class="subtitle"><span id="typed"></span> </div>
|
<div class="subtitle"><span id="typed"></span> </div>
|
||||||
<div class="version">New Version: <span id="version">5.10.7</span></div>
|
<div class="version">New Version: <span id="version">5.11.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>
|
<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>
|
||||||
<div class="down">
|
<div class="down">
|
||||||
@ -206,7 +206,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row number-section">
|
<div class="row number-section">
|
||||||
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
|
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
|
||||||
<div class="numbers">15,121</div>
|
<div class="numbers">15,185</div>
|
||||||
<div class="title">Lines of code</div>
|
<div class="title">Lines of code</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
|
<div class="col-xl-4 col-lg-4 col-md-4 col-12">
|
||||||
|
|||||||
@ -97,6 +97,16 @@
|
|||||||
<td>X</td>
|
<td>X</td>
|
||||||
<td>interface name (differs on Windows)</td>
|
<td>interface name (differs on Windows)</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td>[0].default</td>
|
||||||
|
<td>X</td>
|
||||||
|
<td>X</td>
|
||||||
|
<td>X</td>
|
||||||
|
<td>X</td>
|
||||||
|
<td>X</td>
|
||||||
|
<td>true if this is the default interface</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td>[0].ip4</td>
|
<td>[0].ip4</td>
|
||||||
@ -278,6 +288,7 @@ si.networkInterfaces().then(data => console.log(data));</code></pre class="examp
|
|||||||
{
|
{
|
||||||
iface: 'lo0',
|
iface: 'lo0',
|
||||||
ifaceName: 'lo0',
|
ifaceName: 'lo0',
|
||||||
|
default: false,
|
||||||
ip4: '127.0.0.1',
|
ip4: '127.0.0.1',
|
||||||
ip4subnet: '255.0.0.0',
|
ip4subnet: '255.0.0.0',
|
||||||
ip6: '::1',
|
ip6: '::1',
|
||||||
@ -299,6 +310,7 @@ si.networkInterfaces().then(data => console.log(data));</code></pre class="examp
|
|||||||
{
|
{
|
||||||
iface: 'en0',
|
iface: 'en0',
|
||||||
ifaceName: 'en0',
|
ifaceName: 'en0',
|
||||||
|
default: true,
|
||||||
ip4: '192.168.0.27',
|
ip4: '192.168.0.27',
|
||||||
ip4subnet: '255.255.255.0',
|
ip4subnet: '255.255.255.0',
|
||||||
ip6: 'fe80::134a:1e43:abc5:d413',
|
ip6: 'fe80::134a:1e43:abc5:d413',
|
||||||
@ -318,6 +330,33 @@ si.networkInterfaces().then(data => console.log(data));</code></pre class="examp
|
|||||||
carrierChanges: 0
|
carrierChanges: 0
|
||||||
}, ...
|
}, ...
|
||||||
]</pre>
|
]</pre>
|
||||||
|
<h5>Get Default Interface only</h5>
|
||||||
|
<p> With the 'default' parameter this function returns only the default interface</p>
|
||||||
|
<pre><code class="js">const si = require('systeminformation');
|
||||||
|
si.networkInterfaces('default').then(data => console.log(data));</code></pre class="example">
|
||||||
|
<pre class="example">
|
||||||
|
{
|
||||||
|
iface: 'en0',
|
||||||
|
ifaceName: 'en0',
|
||||||
|
default: true,
|
||||||
|
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,
|
||||||
|
operstate: 'up',
|
||||||
|
type: 'wired',
|
||||||
|
duplex: 'full',
|
||||||
|
mtu: 1500,
|
||||||
|
speed: 1000,
|
||||||
|
dhcp: true,
|
||||||
|
dnsSuffix: '',
|
||||||
|
ieee8021xAuth: '',
|
||||||
|
ieee8021xState: '',
|
||||||
|
carrierChanges: 0
|
||||||
|
}</pre>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>si.networkInterfaceDefault(cb)</td>
|
<td>si.networkInterfaceDefault(cb)</td>
|
||||||
|
|||||||
@ -692,17 +692,29 @@ function testVirtualNic(iface, ifaceName, mac) {
|
|||||||
} else { return false; }
|
} else { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function networkInterfaces(callback, rescan) {
|
function networkInterfaces(callback, rescan, defaultString) {
|
||||||
|
|
||||||
|
if (typeof callback === 'string') {
|
||||||
|
defaultString = callback;
|
||||||
|
rescan = true;
|
||||||
|
callback = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof callback === 'boolean') {
|
if (typeof callback === 'boolean') {
|
||||||
rescan = callback;
|
rescan = callback;
|
||||||
callback = null;
|
callback = null;
|
||||||
|
defaultString = '';
|
||||||
}
|
}
|
||||||
if (typeof rescan === 'undefined') {
|
if (typeof rescan === 'undefined') {
|
||||||
rescan = true;
|
rescan = true;
|
||||||
}
|
}
|
||||||
|
defaultString = defaultString || '';
|
||||||
|
defaultString = '' + defaultString;
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
|
const defaultInterface = getDefaultNetworkInterface();
|
||||||
|
|
||||||
let ifaces = os.networkInterfaces();
|
let ifaces = os.networkInterfaces();
|
||||||
|
|
||||||
let result = [];
|
let result = [];
|
||||||
@ -730,6 +742,7 @@ function networkInterfaces(callback, rescan) {
|
|||||||
result.push({
|
result.push({
|
||||||
iface: nic.iface,
|
iface: nic.iface,
|
||||||
ifaceName: nic.iface,
|
ifaceName: nic.iface,
|
||||||
|
default: nic.iface === defaultInterface,
|
||||||
ip4: nic.ip4,
|
ip4: nic.ip4,
|
||||||
ip4subnet: nic.ip4subnet || '',
|
ip4subnet: nic.ip4subnet || '',
|
||||||
ip6: nic.ip6,
|
ip6: nic.ip6,
|
||||||
@ -750,6 +763,14 @@ function networkInterfaces(callback, rescan) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
_networkInterfaces = result;
|
_networkInterfaces = result;
|
||||||
|
if (defaultString.toLowerCase().indexOf('default') >= 0) {
|
||||||
|
result = result.filter(item => item.default);
|
||||||
|
if (result.length > 0) {
|
||||||
|
result = result[0];
|
||||||
|
} else {
|
||||||
|
result = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
@ -863,6 +884,7 @@ function networkInterfaces(callback, rescan) {
|
|||||||
result.push({
|
result.push({
|
||||||
iface,
|
iface,
|
||||||
ifaceName,
|
ifaceName,
|
||||||
|
default: iface === defaultInterface,
|
||||||
ip4,
|
ip4,
|
||||||
ip4subnet,
|
ip4subnet,
|
||||||
ip6,
|
ip6,
|
||||||
@ -884,6 +906,14 @@ function networkInterfaces(callback, rescan) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_networkInterfaces = result;
|
_networkInterfaces = result;
|
||||||
|
if (defaultString.toLowerCase().indexOf('default') >= 0) {
|
||||||
|
result = result.filter(item => item.default);
|
||||||
|
if (result.length > 0) {
|
||||||
|
result = result[0];
|
||||||
|
} else {
|
||||||
|
result = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
@ -990,6 +1020,7 @@ function networkInterfaces(callback, rescan) {
|
|||||||
result.push({
|
result.push({
|
||||||
iface,
|
iface,
|
||||||
ifaceName,
|
ifaceName,
|
||||||
|
default: iface === defaultInterface,
|
||||||
ip4,
|
ip4,
|
||||||
ip4subnet,
|
ip4subnet,
|
||||||
ip6,
|
ip6,
|
||||||
@ -1011,6 +1042,14 @@ function networkInterfaces(callback, rescan) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_networkInterfaces = result;
|
_networkInterfaces = result;
|
||||||
|
if (defaultString.toLowerCase().indexOf('default') >= 0) {
|
||||||
|
result = result.filter(item => item.default);
|
||||||
|
if (result.length > 0) {
|
||||||
|
result = result[0];
|
||||||
|
} else {
|
||||||
|
result = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user