npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pcap-generator

v0.2.3

Published

Generate PCAP files from packets

Downloads

67

Readme

pcap-generator

Generate PCAP files from packets

# npm install pcap-generator

Usage

pcap-generator can be used both in Node and in the browser. In Node.js it uses the native Buffer and in the browser you have to specify it by calling .configure

Note that it supports both miliseconds (timestamp is an integer) and microseconds (timestamp is a float).

Node.js

const generator = require('pcap-generator')
const fs = require('fs')

const ipPackets = [{
  timestamp: Date.now(), // miliseconds
  buffer: Buffer.from('4500002d000000000011d0970a0a0a0a0b0b0b0b450000210019ffff7b2268656c6c6f223a22776f726c64227d', 'hex')
}]
const pcapFile = generator(ipPackets)

fs.writeFileSync('test.pcap', pcapFile)
console.log('Open test.pcap in Wireshark')

Browser (in this example uses the buffer module)

import { Buffer } from 'buffer'
import { configure } from 'pcap-generator'

const generator = configure({ Buffer: Buffer })
const ipPackets = [{
  timestamp: 1802869.484431046, // microseconds
  buffer: Buffer.from('4500002d000000000011d0970a0a0a0a0b0b0b0b450000210019ffff7b2268656c6c6f223a22776f726c64227d', 'hex')
}]
const pcapFile = generator(ipPackets)

console.log('This here is your pcap file in hex:', pcapFile.toString('hex'))

API

(packets)

packets is an array of of objects similar to:

[{
  timestamp: Date.now(),
  buffer: somePacket
}]

Returns a buffer of the generated pcap file.

.configure(opts)

Returns a new instance of pcap-generator with the passed options.

  • Buffer. Override the Buffer used. Default: Buffer (in Node.js) or none (in the browser)
  • linkLayerType. The type of packets in the file. E.g. 101 for raw IP packets, or 1 for Ethernet packets. See https://www.tcpdump.org/linktypes.html for more details Default: 101 (Raw IP packets)
  • majorVersion. Major version of pcap. Default: 2
  • minorVersion. Minor version of pcap. Default: 4
  • gmtOffset. The GMT offset in pcap. Default: 0
  • timestampAccuracy. The accuracy of the timestamps. Default: 0
  • snapshotLength. The snapshot length of the packets. Default: 65535