Skip to content

Instantly share code, notes, and snippets.

@paolochiodi
Created September 20, 2016 16:33
Show Gist options
  • Save paolochiodi/233d54d7e47b80d639f5ba40edead7f1 to your computer and use it in GitHub Desktop.
Save paolochiodi/233d54d7e47b80d639f5ba40edead7f1 to your computer and use it in GitHub Desktop.
get ip address for given interface
'use strict';
var os = require('os');
function findIp (ifname) {
var ifaces = os.networkInterfaces()
var ifname = ifname || 'eth0'
var iface = ifaces[ifname].find(function (iface) {
if ('IPv4' !== iface.family || iface.internal !== false) {
return false;
}
return true
})
return iface.address
}
module.exports = findIp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment