(I might go to hell for this) way of listing local IPs
var os = require('os');
function localIPs(custom_filter) {
/* default: only IPv4 and non internal */
custom_filter = custom_filter || function (i) { return i.family === 'IPv4' && !i.internal; };
var ni = os.networkInterfaces();
return Array.prototype.concat.apply(Array.prototype,
Object.keys(ni)
.filter(function (k) { return k !== 'lo'; }) /* ignore loopback */
.map(function (k) { return ni[k]; }) /* get value */
) /* flatten */
.filter(custom_filter)
.map(function (a) { return a.address; }); /* get address */
}
console.log(localIPs());
Written by Daniel Tralamazza
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Js
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#