-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
24 lines (23 loc) · 730 Bytes
/
test.js
File metadata and controls
24 lines (23 loc) · 730 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
const { PCap, CONSTANTS } = require("./");
const instance = new PCap({
device: "lo",
callback: (buffer, isTruncated, timestamp) => {
const currentDate = Date.now();
if (currentDate - date >= 1000) {
const currentStats = instance.getStats();
const dropped = currentStats.dropped - stats.dropped;
const pps = currentStats.received - stats.received - dropped;
console.log("[JS_onPacket]", `${pps}/sec, dropped: ${dropped}`);
stats = currentStats;
date = currentDate;
}
},
});
let stats = instance.getStats();
let date = Date.now();
try {
instance.startCapture(CONSTANTS.DIRECTION.BOTH);
setTimeout(() => instance.stopCapture(), 10000);
} catch (ex) {
console.error(ex);
}