Skip to content

Instantly share code, notes, and snippets.

@itaysk
Created August 3, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itaysk/6929551600d96c46d1fb to your computer and use it in GitHub Desktop.
Save itaysk/6929551600d96c46d1fb to your computer and use it in GitHub Desktop.
Web App that shows the IP address of the server
var http = require('http');
var os = require('os');
var msg = "";
var ifaces = os.networkInterfaces();
Object.keys(ifaces).forEach(function (ifname) {
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;
}
console.log(iface.address);
msg += iface.address + '\n';
});
});
var server = http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
res.end(msg);
});
server.listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment