Network

In this section you will learn how to get detailed information about network interfaces, network connections and statistics as well as some internet related information (latency, check availability of site):

For function reference and examples we assume, that we imported systeminformation as follows:

const si = require('systeminformation');

Network Interfaces, Network Stats, Network Connections

All functions in this section return a promise or can be called with a callback function (parameter cb in the function reference)

Function Result object Linux BSD Mac Win Sun Comments
si.networkInterfaces(cb) [{...}] X X X X X array of network interfaces (objects)
[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].ip6 X X X X X ip6 address
[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
[0].operstate X X X up / down
[0].type X X X wireless / wired
[0].duplex X X duplex (full/half)
[0].mtu X X MUT maximum transmission unit
[0].speed X X X Speed in Mbit / s
[0].carrierChanges X # changes up/down
si.networkInterfaceDefault(cb) : string X X X X X get name of default network interface
si.networkStats(iface,cb) [{...}] X X X X current network stats of given interfaces,
iface list: comma separated,
iface parameter is optional,
defaults to first external network interface,
pass '*' for all interfaces
[0].iface X X X X interface
[0].operstate X X X X up / down
[0].rx_bytes X X X X received bytes overall
[0].rx_dropped X X X X received dropped overall
[0].rx_errors X X X X received errors overall
[0].tx_bytes X X X X transferred bytes overall
[0].tx_dropped X X X X transferred dropped overall
[0].tx_errors X X X X transferred errors overall
[0].rx_sec X X X X received bytes / second (* see notes)
[0].tx_sec X X X X transferred bytes per second (* see notes)
[0].ms X X X X interval length (for per second values)
si.networkConnections(cb) [{...}] X X X X current network network connections
returns an array of all connections
[0].protocol X X X X tcp or udp
[0].localaddress X X X X local address
[0].localport X X X X local port
[0].peeraddress X X X X peer address
[0].peerport X X X X peer port
[0].state X X X X like ESTABLISHED, TIME_WAIT, ...
[0].pid X X X X process ID
[0].process X X process name

Site availability, Internet Latency

Function Result object Linux BSD Mac Win Sun Comments
si.inetChecksite(url, cb) {...} X X X X X response-time (ms) to fetch given URL
url X X X X X given url
ok X X X X X status code OK (2xx, 3xx)
status X X X X X status code
ms X X X X X response time in ms
si.inetLatency(host, cb) : number X X X X X response-time (ms) to external resource
host parameter is optional (default 8.8.8.8)

Getting correct stats values

In networkStats() the results / sec. values (rx_sec, tx_sec, ...) are calculated correctly beginning with the second call of the function. It is determined by calculating the difference of transferred bytes / IOs divided by the time between two calls of the function.

The first time you are calling one of this functions, you will get -1 for transfer rates. The second time, you should then get statistics based on the time between the two calls ...

So basically, if you e.g. need a values for filesystem stats stats every second, your code should look like this:

const si = require('systeminformation');

setInterval(function() {
    si.networkStats().then(data => {
        console.log(data);
    })
}, 1000)

Beginning with the second call, you get network transfer values per second.