I am using Wireshark's Tshark cmd tool to capture some network packets and analyze them. In order to generate working environment, you only need Wireshark 3+ and NodeJS 9+. I am using following code to cut the Tshark flow at a certain time (setTimeout is used to simulate a simultaneous Stop button click of the user)
var spawn = require('child_process').spawn,
ts = spawn('tshark', ['-i', 'Wi-Fi', '-T', 'json']);
function analyzePacket(packet) {
console.log(packet.toString());
}
ts.stdout.on('data', function (packet) {
analyzePacket(packet)
});
setTimeout(function(){ ts.kill(); }, 5000);
This works well however, when the ts.kill();
is called, writing the packet information to the screen is cut in the middle. I want the tshark to fully output the last packet that is captured before stop button (ts.kill() is fired) is clicked. I tried sending different kind of signals which differs in the killing harshness as far as I know. That are the following :
ts.kill('SIGINT');
ts.kill('SIGHUP');
ts.kill('SIGKILL');
None of them seems to be working. That is the best way to achieve final packet fully, then close gracefully.