Skip to content

Instantly share code, notes, and snippets.

@iponkan
Created December 6, 2019 01:26
Show Gist options
  • Save iponkan/7048de232383ef41dd2fc369a4e52284 to your computer and use it in GitHub Desktop.
Save iponkan/7048de232383ef41dd2fc369a4e52284 to your computer and use it in GitHub Desktop.
const os = require('os');
let ip = '0.0.0.0';
const networkInterfaces = os.networkInterfaces();
out:
for (const i in networkInterfaces) {
for (const j in networkInterfaces[i]) {
const val = networkInterfaces[i][j];
if (val.family === 'IPv4' && val.address !== '127.0.0.1') {
ip = val.address;
break out
}
}
}
module.exports = ip;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment