Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created July 2, 2014 13:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosePedroDias/76e477396c48d03c0a2f to your computer and use it in GitHub Desktop.
Save JosePedroDias/76e477396c48d03c0a2f to your computer and use it in GitHub Desktop.
returns object with network interface name -> IP address
var os = require('os');
var getMyIPs = function() {
var ips = {};
var ifaces = os.networkInterfaces();
var onDetails = function(details) {
if (details.family === 'IPv4') {
ips[ dev ] = details.address;
}
};
for (var dev in ifaces) {
ifaces[dev].forEach(onDetails);
}
return ips;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment