Last active
August 2, 2016 10:19
-
-
Save mcasimir/19f587ec0ca147934ffb52c6157bb8a1 to your computer and use it in GitHub Desktop.
kube node app
This file contains hidden or 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
var os = require("os"); | |
var ifaces = os.networkInterfaces(); | |
var myIfaces = {}; | |
Object.keys(ifaces).forEach(function (ifname) { | |
var alias = 0; | |
ifaces[ifname].forEach(function (iface) { | |
if ('IPv4' !== iface.family || iface.internal !== false) { | |
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses | |
return; | |
} | |
if (alias >= 1) { | |
myIfaces[ifname + ':' + alias] = iface.address; | |
} else { | |
myIfaces[ifname] = iface.address; | |
} | |
++alias; | |
}); | |
}); | |
require('http').createServer((request, response) => { | |
response.writeHead(200, {'Content-Type': 'application/json'}); | |
response.end(JSON.stringify({ | |
requestHost: request.headers.host, | |
osHostname: os.hostname(), | |
net: myIfaces | |
}, null, 2)); | |
}).listen(3000, () => { | |
console.log('Server listening ...'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment