fix: intermittent error when asking for interfaces (#137)

Get interfaces only once per run
This commit is contained in:
Mikeal Rogers 2020-12-28 01:49:48 -08:00 committed by GitHub
parent e9e1f56b87
commit af9804e778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,8 +29,9 @@ function isAnyAddr (ip) {
* @param {string} family One of ['IPv6', 'IPv4']
* @returns {string[]} an array of ip address strings
*/
const networks = os.networkInterfaces()
function getNetworkAddrs (family) {
return Object.values(os.networkInterfaces()).reduce((addresses, netAddrs) => {
return Object.values(networks).reduce((addresses, netAddrs) => {
netAddrs.forEach(netAddr => {
// Add the ip of each matching network interface
if (netAddr.family === family) addresses.push(netAddr.address)