Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bandwidth-monitor

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bandwidth-monitor - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

15

example.js

@@ -6,5 +6,12 @@ const BandwidthMonitor = require('.');

console.log(Object.keys(b.monitors));
setInterval(() => {
console.log(b.monitors.en0.rxPerSec);
// b.monitors.en0.close();
}, 1000);
try{
b.monitors.en0.capture();
setInterval(() => {
console.log(b.monitors.en0.rxPerSec);
// b.monitors.en0.close();
}, 1000);
}catch (e) {
console.log('need root ! add sudo command.');
}

@@ -7,3 +7,2 @@

const bufSize = 10 * 1024 * 1024;
const buffer = new Buffer(bufSize);

@@ -51,4 +50,4 @@ function isIPv4(string) {

this.cap = new Cap();
//todo(cc): catch permission denied warning
const link = this.cap.open(device.name, '', bufSize, buffer);
this.device = device;
this.totalRx = 0;

@@ -58,10 +57,18 @@ this.totalTx = 0;

this.txPerSec = 0;
this.buffer = new Buffer(bufSize);
}
capture(){
//need root
this.link = this.cap.open(this.device.name, '', bufSize, this.buffer);
this.cap.on('packet', (size) => {
if (link === 'ETHERNET') {
let ret = decoders.Ethernet(buffer);
if (this.link === 'ETHERNET') {
let ret = decoders.Ethernet(this.buffer);
//todo(cc): support ipv6
if (ret.info.type === PROTOCOL.ETHERNET.IPV4) {
ret = decoders.IPV4(buffer, ret.offset);
if (ret.info.srcaddr !== device.ipv4) {
ret = decoders.IPV4(this.buffer, ret.offset);
if (ret.info.srcaddr !== this.device.ipv4) {
this.totalRx += size;

@@ -89,2 +96,4 @@ } else {

this.cap.close();
this.buffer = null;
}

@@ -91,0 +100,0 @@ }

{
"name": "bandwidth-monitor",
"version": "1.0.2",
"version": "1.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc