Created
August 8, 2018 12:00
-
-
Save xgz123/a14a344b25471ad1b5533b3c6d3b5532 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
const ips = require('os').networkInterfaces() | |
const result = [] | |
Object.keys(ips).forEach(function (ifname) { | |
ips[ifname].forEach(function (iface) { | |
if ('IPv4' !== iface.family || iface.internal !== false) { | |
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses | |
return; | |
} | |
result.push(iface.address) | |
}); | |
}); | |
module.exports = result[0] ? result[0] : '0.0.0.0' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment