Skip to content

Instantly share code, notes, and snippets.

@itaysk

itaysk/Show_IP.js

Created Aug 3, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.