From 78624c670f355cbed21278056fcc4fbc85277a6f Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 11 Feb 2018 22:08:37 +0100 Subject: [PATCH] extended FreeBSD support networkConnections() --- CHANGELOG.md | 1 + README.md | 18 +++++++++--------- lib/index.js | 12 +++++------- lib/network.js | 3 ++- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 284af2a..5cf17cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.36.0 | 2018-02-11 | extended FreeBSD support `networkConnections()` | | 3.35.0 | 2018-02-11 | extended FreeBSD support `processLoad()` | | 3.34.1 | 2018-02-11 | updated docs | | 3.34.0 | 2018-02-10 | first partial FreeBSD support | diff --git a/README.md b/README.md index ac8f5bf..c9b12b1 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,13 @@ async function cpu() { ### Latest Activity (last 7 major and minor version releases) +- Version 3.36.0: extended FreeBSD support `networkConnections()` +- Version 3.35.0: extended FreeBSD support `processLoad()` - Version 3.34.0: first partial FreeBSD support - Version 3.33.0: added bios `bios()` and main board `baseboard()` information - Version 3.32.0: extended `memLayout()` - added manufacturer - Version 3.31.0: extended windows support `cpuFlags()` (partially) - Version 3.30.0: extended `versions()` (added `yarn`, `gulp`, `grunt`, `tsc`, `git`) -- Version 3.29.0: extended windows support `services()` -- Version 3.28.0: extended windows support `processes()` - ... You can find all changes here: [detailed changelog][changelog-url] @@ -297,13 +297,13 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | rx_sec | X | | X | X | received bytes / second (* see notes) | | | tx_sec | X | | X | X | transferred bytes per second (* see notes) | | | ms | X | | X | X | interval length (for per second values) | -| si.networkConnections(cb) | [{...}] | X | | X | X | current network network connections
returns an array of all connections| -| | [0].protocol | X | | X | X | tcp or udp | -| | [0].localaddress | X | | X | X | local address | -| | [0].localport | X | | X | X | local port | -| | [0].peeraddress | X | | X | X | peer address | -| | [0].peerport | X | | X | X | peer port | -| | [0].state | X | | X | X | like ESTABLISHED, TIME_WAIT, ... | +| 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, ... | | si.inetChecksite(url, cb) | {...} | X | X | X | X | response-time (ms) to fetch given URL | | | url | X | X | X | X | given url | | | ok | X | X | X | X | status code OK (2xx, 3xx) | diff --git a/lib/index.js b/lib/index.js index e782c39..c4f9a8a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -187,7 +187,7 @@ function getDynamicData(srv, iface, callback) { let functionProcessed = (function () { let totalFunctions = 14; if (_windows) totalFunctions = 10; - if (_freebsd || _openbsd) totalFunctions = 10; + if (_freebsd || _openbsd) totalFunctions = 11; return function () { if (--totalFunctions === 0) { @@ -255,12 +255,10 @@ function getDynamicData(srv, iface, callback) { }); } - if (!_openbsd && !_freebsd) { - network.networkConnections().then(res => { - data.networkConnections = res; - functionProcessed(); - }); - } + network.networkConnections().then(res => { + data.networkConnections = res; + functionProcessed(); + }); memory.mem().then(res => { data.mem = res; diff --git a/lib/network.js b/lib/network.js index b853682..ceb8a65 100644 --- a/lib/network.js +++ b/lib/network.js @@ -403,8 +403,9 @@ function networkConnections(callback) { return new Promise((resolve) => { process.nextTick(() => { let result = []; - if (_linux) { + if (_linux || _freebsd || _openbsd) { let cmd = 'netstat -tuna | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN\\|VERBUNDEN"'; + if (_freebsd || _openbsd) cmd = 'netstat -na | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN\\|VERBUNDEN"' exec(cmd, function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n');