@cto.af/pcap-ng-parser is a stream-based module to decode, print and analyze network traffic packets. With this module, you can read from an existing .pcap or .pcapng file or connect it to an active stream.
Implements:
This module is available through the npm registry.
$ npm install @cto.af/pcap-ng-parser
Here is a quick example of how to log out packets to the console from a valid .pcapng file named myfile.pcapng.
import PCAPNGParser from '@cto.af/pcap-ng-parser';
import fs from 'node:fs';
const pcapNgParser = new PCAPNGParser();
const myFileStream = fs.createReadStream('./myfile.pcapng');
myFileStream.pipe(pcapNgParser)
.on('data', parsedPacket => {
console.log(parsedPacket);
})
.on('interface', interfaceInfo => {
console.log(interfaceInfo);
});
In the example above, we create a new Readable stream from our file and pipe the instance pcapNgParser which will read our packet data on the _transform event.
You can also pipe from TCPDump using process.stdin for a command line interaction.
import PCAPNGParser from '@cto.af/pcap-ng-parser';
const pcapNgParser = new PCAPNGParser();
process.stdin.pipe(pcapNgParser)
.on('data', parsedPacket => {
console.log(parsedPacket);
})
.on('interface', interfaceInfo => {
console.log(interfaceInfo);
});
$ sudo tcpdump -w - | node exampleAbove.js
Note that in order to utilize tcpdump you must be a superuser. Refer to tcpdump documentation for details.
Further note: If you specify an interface to listen on with "-i", tcpdump no longer uses the pcapng format.
Additional examples can be found in the examples directory.
It allows you to read from a sample capture file (the default), a file (if you specify a file name on the command line), or stdin (if you specify "-" as the input file).
PCAPNGParser is an extension of the stream.Transform class. The PCAPNGParser class fires the following events:
data: An Enhanced Packet or Simple block was parsed.section: A Section Header block was parsed.interface: An Interface block was parsed.names: A Name Resolution block was parsed.secrets: A Decryption Secrets block was parsed.stats: An Interface Statistics block was parsed.custom: A Custom block was parsed.blockType: An unknown block type has been received.See the full API documentation for the types of the event parameters.
Refer to the the Contribution Guide for details on how to contribute.
This module is covered under the BSD-3 Open Software License. Review the License Documention for more information.
This code was forked from https://github.com/CollinearGroup/pcap-ng-parser due to lack of maintenance. To simplify matters, copyright remains with the original authors, including all changes made in this repository. If the original authors contact me (easiest would be to file an issue here), all of this can be changed in any way that suits them.
The following things have been added: