DEV Community

Cover image for Packet Sniffing tool implemented in Node.js (alternatives to Charles, hoxy, etc...)
Kohei Ueno
Kohei Ueno

Posted on

1 2

Packet Sniffing tool implemented in Node.js (alternatives to Charles, hoxy, etc...)

Illustration by Stories by Freepik

GitHub logo cola119 / ESniffer

Modern network analyze tool. Alternatives to Hoxy, Charles, etc.

ESniffer πŸ”¬

Modern network analyze tool. Alternatives to Hoxy, Charles, etc.

Install

npm i esniffer
yarn add esniffer
Enter fullscreen mode Exit fullscreen mode

Example

// index.js
import ESniffer from "esniffer";
import fs from "fs";
// Required if you want to monitor over HTTPS
const key = fs.readFileSync(`path/to/root-key.pem`);
const cert = fs.readFileSync(`path/to/root-cert.pem`);

const proxy = ESniffer.createServer({ secure: { key, cert } });
proxy.listen(8080);

proxy.on("request", (req) => {
  req.pipe(process.stdout);
});
proxy.on("response", (res) => {
  res.pipe(process.stdout);
});
proxy.on("info", (info) => {
  console.log(info);
}
…
Enter fullscreen mode Exit fullscreen mode

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. I'm a heavy user of Charles for debugging but sometimes struggle with its lack of customization.

If we can monitor HTTP/HTTPS traffic using Node.js script, we can do even more useful debugging and testing. So I've developed a simple module that allows for packet monitoring.

import ESniffer from "esniffer";
import fs from "fs";

// Required if you want to monitor over HTTPS
const key = fs.readFileSync(`path/to/root-key.pem`);
const cert = fs.readFileSync(`path/to/root-cert.pem`);

const proxy = ESniffer.createServer({ secure: { key, cert } });
proxy.listen(8080);

proxy.on("request", (req) => {
  req.pipe(process.stdout);
});
proxy.on("response", (res) => {
  res.pipe(process.stdout);
});
proxy.on("info", (info) => {
  console.log(info);
});
proxy.on("error", (e) => {
  console.error(e.message);
});
Enter fullscreen mode Exit fullscreen mode

This is inheriting the EventEmitter so we can access request to the server and response from the server via custom events. By installing and trusting a self-signed certificate, we can also monitor over HTTPS communication. See examples for more information.

Finally, I welcome bug reports and requests for additional features. Github Star, please!

GitHub logo cola119 / ESniffer

Modern network analyze tool. Alternatives to Hoxy, Charles, etc.

ESniffer πŸ”¬

Modern network analyze tool. Alternatives to Hoxy, Charles, etc.

Install

npm i esniffer
yarn add esniffer
Enter fullscreen mode Exit fullscreen mode

Example

// index.js
import ESniffer from "esniffer";
import fs from "fs";
// Required if you want to monitor over HTTPS
const key = fs.readFileSync(`path/to/root-key.pem`);
const cert = fs.readFileSync(`path/to/root-cert.pem`);

const proxy = ESniffer.createServer({ secure: { key, cert } });
proxy.listen(8080);

proxy.on("request", (req) => {
  req.pipe(process.stdout);
});
proxy.on("response", (res) => {
  res.pipe(process.stdout);
});
proxy.on("info", (info) => {
  console.log(info);
}
…
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay