Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require("fs");
- const targetIP = "192.168.4.13";
- const networkInterface = "wlan0";
- let previousRx = 0;
- let previousTx = 0;
- function getNetworkStats() {
- try {
- const data = fs.readFileSync("/proc/net/dev", "utf8");
- const lines = data.split("\n");
- const ifaceLine = lines.find(line => line.includes(networkInterface));
- if (!ifaceLine) {
- console.error(`Schnittstelle ${networkInterface} nicht gefunden.`);
- return;
- }
- const stats = ifaceLine.trim().split(/\s+/);
- const rxBytes = parseInt(stats[1], 10);
- const txBytes = parseInt(stats[9], 10);
- const rxDelta = previousRx ? rxBytes - previousRx : 0;
- const txDelta = previousTx ? txBytes - previousTx : 0;
- previousRx = rxBytes;
- previousTx = txBytes;
- console.log(`[${new Date().toISOString()}] RX: ${rxDelta} Bytes, TX: ${txDelta} Bytes`);
- } catch (err) {
- console.error("Fehler beim Abrufen der Netzwerkdaten:", err.message);
- }
- }
- setInterval(getNetworkStats, 1000);
Advertisement
Add Comment
Please, Sign In to add comment