Skip to content

Instantly share code, notes, and snippets.

@alsotang
Created May 11, 2021 08:09
Show Gist options
  • Save alsotang/9c6768506e3e2325c4a2b75484982de2 to your computer and use it in GitHub Desktop.
Save alsotang/9c6768506e3e2325c4a2b75484982de2 to your computer and use it in GitHub Desktop.
get lan ip in node.js
const os = require('os')
function getLanAddress() {
const ifaces = os.networkInterfaces();
if (ifaces) {
for (const dev of Object.keys(ifaces)) {
for (const details of ifaces[dev]) {
if (details.family === 'IPv4' && details.mac !== '00:00:00:00:00:00') {
return details.address;
}
}
}
}
return '127.0.0.1';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment