-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (25 loc) · 799 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require("express");
const app = express();
const os = require("os");
const port = 8080;
app.get("/", (req, res) => {
const nets = os.networkInterfaces();
const results = Object.create(null); // or just '{}', an empty object
var hostname = os.hostname().split('.').shift()
for (const name of Object.keys(nets)) {
for (const net of nets[name]) {
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses
if (net.family === "IPv4" && !net.internal) {
if (!results[name]) {
results[name] = [];
}
results[name].push(net.address);
}
}
}
results["hostname"] = hostname;
res.send(JSON.stringify(results));
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});