pcap-parser is a Node.js module designed to parse `.pcap` packet capture files. Originally published in 2012, its current and last stable version is 0.2.1. This library focuses on the raw parsing of pcap file headers and individual packet data, emitting events for global header, packet header, packet data, and complete packets. It strictly supports only version 2.4 of the `libpcap` file format in both big-endian and little-endian formats. Due to its age, it primarily caters to older Node.js environments (engine requirement `>=0.6.0`) and does not support the newer `pcapng` format or provide high-level protocol decoding. Its release cadence is non-existent, as it has not been updated in over a decade. While functional for its specific, limited purpose, developers should be aware of its lack of maintenance and consider modern alternatives for broader compatibility or advanced features.
npm install pcap-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate the PCAP parser with a file path, listen for `globalHeader`, `packet`, and `end` events, and then initiate the parsing process. It includes a small self-contained dummy pcap file creation for immediate execution.
Consider using modern alternatives like `@cto.af/pcap-ng-parser` or `pcap-ng-parser` for `pcapng` files and broader compatibility, or `node-pcap` for live capture and potentially better maintenance, though also quite old. If possible, use external tools (e.g., `tshark`) for parsing and pipe output.
Ensure your `.pcap` files are in the legacy `libpcap` format (version 2.4). If you have `.pcapng` files, convert them to `.pcap` using tools like Wireshark/tshark, or use a `pcapng`-specific parser library.
If used in an ESM module, wrap the import in a dynamic `import()` statement or configure your project to allow CommonJS interoperability (e.g., by using an older Node.js version or a bundler that handles CJS-in-ESM).
Always register an `error` event listener on the `Parser` instance to gracefully handle file I/O errors, corruption, or other parsing issues: `parser.on('error', (err) => console.error('Parsing error:', err));`Ensure you are using `new pcapp.Parser()` with a capital 'P' for the constructor.
Verify that the file path provided to the `pcapp.Parser` constructor is correct and that the Node.js process has read permissions for the file.
Run `npm install pcap-parser` in your project directory to ensure the package is installed and available.
No dependency data recorded yet.