pcap-writer

Simple pcap writer for node

Usage no npm install needed!

<script type="module">
  import pcapWriter from 'https://cdn.skypack.dev/pcap-writer';
</script>

README

pcap-writer

A simple pcap writer based on the core of node-pcap-writer, from Harsh Raval.

Example

Initialize:

const pcapw = require('pcpa-writer');

const pcapWriter = pcapw.createPcapWriter('file.pcap', 1500, 105);

This will also write global header. Then for writing data packets:


pcapWriter.writePacket(packet, timestamp);

Here packet is a Buffer object of Node JS containig data of packet. Timestamp needs to be in usec, if not set the packet will be written with the current relative timestamp.

And then finally close it:


pcapWriter.close();

This will close the file write stream so the file can be usable.

If you like, you can also add a callback function, to be called as soon as the writer finishes writing the last packet:


pcapWriter.close( (filename, elapsedTime) => {
    
    //your code here

} );

License

MIT