congress
Version:
Broadcast/Multicast/Unicast discovery and communication library. Sets up and maintains connections between two or more nodes over a network. Supports discovery and message passing between individual or all nodes.
23 lines (17 loc) • 478 B
JavaScript
;
var IPUtils = {};
IPUtils.GetIPAddress = function() {
var os = require('os');
var interfaces = os.networkInterfaces();
var found = null;
Object.keys(interfaces).forEach(function(name) {
if (found) return;
interfaces[name].forEach(function (inface) {
if (found) return;
if (inface.family!=="IPv4" || inface.internal) return;
found = inface;
});
});
return found && found.address || null;
};
module.exports = IPUtils;