-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (35 loc) · 1011 Bytes
/
index.js
File metadata and controls
40 lines (35 loc) · 1011 Bytes
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
32
33
34
35
36
37
38
39
40
const express = require('express');
const os = require('os');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
const interfaces = os.networkInterfaces();
let ipAddress = 'Unknown';
for (const iface of Object.values(interfaces)) {
for (const details of iface) {
if (details.family === 'IPv4' && !details.internal) {
ipAddress = details.address;
break;
}
}
}
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Container IP Address</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>Container IP Address</h1>
<p>IP: ${ipAddress}</p>
</body>
</html>
`);
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});