output network interfaces

This commit is contained in:
AJ ONeal 2016-09-08 23:10:04 -06:00
parent d62e4ed8d8
commit f4c76a8bf7
2 changed files with 71 additions and 2 deletions

45
local-ip.js Normal file
View File

@ -0,0 +1,45 @@
'use strict';
var os = require('os');
module.exports.find = function () {
var ifaceMap = os.networkInterfaces();
var newMap = {};
Object.keys(ifaceMap).forEach(function (iname) {
var ifaces = ifaceMap[iname];
ifaces = ifaces.filter(function (iface) {
return !iface.internal && !/^fe80/.test(iface.address) && !/^[0:]+$/.test(iface.mac);
});
if (!ifaces.length) {
return;
}
newMap[iname] = newMap[iname] || { ipv4: [], ipv6: [] };
ifaces.forEach(function (addr) {
addr.iface = iname;
if ('IPv4' === addr.family) {
newMap[iname].ipv4.push(addr);
}
else if ('IPv6' === addr.family) {
newMap[iname].ipv6.push(addr);
}
});
});
return newMap;
/*
https://[2601:681:300:92c0:2477:d58a:d69e:51a0]:8443
console.log('');
console.log('');
console.log(iname);
console.log(ifaces);
console.log('');
*/
};

View File

@ -59,6 +59,28 @@ function createServer(port, pubdir, content, opts) {
console.info(msg);
console.info('');
console.info('\t' + httpsUrl);
Object.keys(opts.ifaces).forEach(function (iname) {
var iface = opts.ifaces[iname];
if (iface.ipv4.length) {
console.info('');
console.info(iname + ':');
httpsUrl = 'https://' + iface.ipv4[0].address;
if (443 !== p) {
httpsUrl += ':' + p;
}
console.info('\t' + httpsUrl);
httpsUrl = 'https://[' + iface.ipv6[0].address + ']';
if (443 !== p) {
httpsUrl += ':' + p;
}
if (iface.ipv6.length) {
console.info('\t' + httpsUrl);
}
}
});
console.info('');
});
@ -83,14 +105,16 @@ function run() {
var pubdir = path.resolve(argv.d || argv._[1] || process.cwd());
var content = argv.c;
var letsencryptHost = argv['letsencrypt-certs'];
var tls = require('tls');
var cert = require('localhost.daplie.com-certificates');
var opts = {
key: cert.key
ifaces: require('./local-ip.js').find()
, key: cert.key
, cert: cert.cert
//, ca: cert.ca
, SNICallback: function (servername, cb) {
cb(null, require('tls').createSecureContext(opts));
cb(null, tls.createSecureContext(opts));
return;
}
};