Created
September 20, 2016 16:33
-
-
Save paolochiodi/233d54d7e47b80d639f5ba40edead7f1 to your computer and use it in GitHub Desktop.
get ip address for given interface
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
'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