Skip to content

Instantly share code, notes, and snippets.

@xgz123
Created August 8, 2018 12:00
Show Gist options
  • Save xgz123/a14a344b25471ad1b5533b3c6d3b5532 to your computer and use it in GitHub Desktop.
Save xgz123/a14a344b25471ad1b5533b3c6d3b5532 to your computer and use it in GitHub Desktop.
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