Created
August 29, 2018 17:31
-
-
Save knyga/70b7704751aee1c5080fd9e1c4495991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function detectLocalIps() { | |
const networkInterfaces = require('os').networkInterfaces(); | |
return Object.keys(networkInterfaces).reduce((acc, interfaceKey) => { | |
const filterIpsList = ['127.0.0.1', '::']; | |
const interfaceDetails = networkInterfaces[interfaceKey]; | |
for(let i=0; i<interfaceDetails.length; i++) { | |
const locator = interfaceDetails[i]; | |
if(locator && locator.hasOwnProperty('address') && locator.hasOwnProperty('family') && locator.family === 'IPv4') { | |
let isAllowed = true; | |
for(let j=0; isAllowed && j < filterIpsList.length; j++) { | |
if(locator.address.includes(filterIpsList[j])) { | |
isAllowed = false; | |
} | |
} | |
if(isAllowed) { | |
acc.push(locator.address); | |
} | |
} | |
} | |
return acc; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment