-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmock-api-server.js
More file actions
62 lines (55 loc) · 1.66 KB
/
mock-api-server.js
File metadata and controls
62 lines (55 loc) · 1.66 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
app.use(express.json());
// Root route
app.get('/', (req, res) => {
res.json({
message: 'Mini Wireshark API Server',
endpoints: [
'GET /api/packets - Get captured packets',
'GET /api/stats - Get packet statistics'
]
});
});
// Mock packet data
const generateMockPackets = () => {
const packets = [];
const protocols = ['TCP', 'UDP', 'ICMP'];
const sources = ['192.168.1.100', '192.168.1.101', '192.168.1.102', '10.0.0.5'];
const destinations = ['8.8.8.8', '1.1.1.1', '172.16.0.1'];
for (let i = 1; i <= 20; i++) {
packets.push({
id: i,
timestamp: new Date().toISOString().slice(0, 19).replace('T', ' '),
source: sources[Math.floor(Math.random() * sources.length)],
destination: destinations[Math.floor(Math.random() * destinations.length)],
protocol: protocols[Math.floor(Math.random() * protocols.length)],
length: 64 + (i * 10),
info: protocols[i % 3] === 'TCP' ? 'HTTP GET Request' : 'DNS Query'
});
}
return packets;
};
// API Endpoints
app.get('/api/packets', (req, res) => {
res.json({ packets: generateMockPackets() });
});
app.get('/api/stats', (req, res) => {
res.json({
totalPackets: 20,
tcpPackets: 12,
udpPackets: 6,
icmpPackets: 2,
ethernetPackets: 20,
errorPackets: 0
});
});
const PORT = 8080;
app.listen(PORT, () => {
console.log(`Mock API server running on http://localhost:${PORT}`);
console.log(`Endpoints:`);
console.log(` GET http://localhost:${PORT}/api/packets`);
console.log(` GET http://localhost:${PORT}/api/stats`);
});