Created
August 3, 2015 13:38
-
-
Save itaysk/6929551600d96c46d1fb to your computer and use it in GitHub Desktop.
Web App that shows the IP address of the server
This file contains 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 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