-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
70 lines (59 loc) · 2.04 KB
/
server.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
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
63
64
65
66
67
68
69
70
const express = require("express");
const http = require("http");
const socketIo = require("socket.io");
const path = require("path");
const { scanWifiNetworks } = require("./wifiScanner");
const { startMonitoring } = require("./networkMonitor");
const { startCapture } = require("./pcapCapture");
const app = express();
const server = http.createServer(app);
const io = socketIo(server);
app.use(express.static(path.join(__dirname, "public")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));
});
app.get("/packets", (req, res) => {
res.sendFile(path.join(__dirname, "packets.html"));
});
app.get("/wifi", (req, res) => {
res.sendFile(path.join(__dirname, "wifi.html"));
});
io.on("connection", (socket) => {
console.log("A user connected:", socket.id);
socket.on("disconnect", () => {
console.log("User disconnected:", socket.id);
});
// Start WiFi scan when requested
socket.on("startWifiScan", () => {
console.log("Starting WiFi scan...");
scanWifiNetworks((networks, newDevices) => {
socket.emit("wifiScanResults", networks);
socket.emit("newWiFiDeviceAlert", newDevices);
});
// Start periodic WiFi scan
setInterval(() => {
scanWifiNetworks((networks, newDevices) => {
socket.emit("newWiFiDeviceAlert", newDevices);
socket.emit("wifiScanResults", networks);
});
}, 10000); // Send time to client every 10 seconds
});
// Start packet capture when requested
socket.on("startPacketCapture", () => {
console.log("Starting packet capture...");
startCapture((packet) => {
socket.emit("packet", packet);
});
});
// Start local network monitoring when requested
socket.on("startLocalNetworkMonitoring", () => {
console.log("Starting local network monitoring...");
startMonitoring((newDevices, allDevices) => {
socket.emit("newLocalDeviceAlert", newDevices);
socket.emit("allLocalDevices", allDevices);
});
});
});
server.listen(3000, () => {
console.log("Server is running on http://localhost:3000");
});