Skip to content

harryjoy/node-pcap-writer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-pcap-writer

A simple pcap writer that helps you to create pcap file from captured packet data in Node JS.

Background

There are reader and parser packages available for pcap in Node JS but not writer so decided to write onde that can help others.

Example

Initialize:

var PcapWriter = require('../index');
...
var pcapWriter = new PcapWriter('./test.pcap', 1500, 105);
...

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

...
pcapWriter.writePacket(packetDataBuffer, timestamp)
...

Here packetDataBuffer is Buffer object of Node JS containig data of packet. Timestamp needs to be in usec. And then finally close it:

...
pcapWriter.close();
...

This will close the file write stream so the file can be usable. Don't forget to close it when you are done writing all packets.

License

MIT