-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
91 lines (76 loc) · 3 KB
/
index.js
File metadata and controls
91 lines (76 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var fs = require('fs');
var walk = require('walk');
var json2csv = require('json2csv');
/**********************************************************************************************************/
var files = [];
var counter = 0;
var i=0;
var mytimer;
var dataArray = [{}];
var fields=['Episode', 'A', 'B', 'AtoB (bit/s)','BtoA (bit/s)'];
console.log("please wait, this may take a few minutes...")
function pcap2csv(path,tcp_udp){
// Walker options
var walker = walk.walk(path, {
followLinks: false
});
// find all files and add them to an array
walker.on('file', function (root, stat, next) {
// console.log(stat.name);
files.push(root + '/' + stat.name);
next();
});
walker.on('end', function () {
console.log('reading ended')
mytimer = setInterval(processor,1000);
//processor()
//setTimeout(function(){console.log("done")}, 3000);
});
function processor(cb){
// console.log(files)
if(files[i]){
if(files[i].split('.')[1]=='pcap'){
// console.log(files[i])
var separates = files[i].split('/');
require('child_process').exec('tshark -nr '+files[i]+' -z conv,'+tcp_udp+' -q',
(err, stdout, stderr) => {
if (err) {
console.log(err.message);
// node couldn't execute the command
}
// the *entire* stdout and stderr (buffered)
// **uncomment to write the output of .pcap files to individual .txt files instead**/
// fs.writeFile(path+'/'+separates[separates.length-1].split('.')[0] +'.txt', data, function (err) {
// console.log(path+'/'+separates[separates.length-1].split('.')[0] +'.txt');
// if (err) throw err;
// });
console.log(stdout)
var array = stdout.toString().split("|");
var line = array[array.length-1];
var linearray = line.match(/\S+/g) || [];
while (linearray.length>11){
var AtoB = parseFloat(linearray[6]) * 8 / parseFloat(linearray[10]);
var BtoA = parseFloat(linearray[4]) * 8 / parseFloat(linearray[10]);
dataArray.push({Episode:i, A:linearray[0], B:linearray[2], 'AtoB (bit/s)':AtoB, 'BtoA (bit/s)':BtoA});
linearray.splice(0, 11)
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
i++;
}
else(i++);
}
else {
clearInterval(mytimer)
var csv = json2csv({ data: dataArray, fields: fields, hasCSVColumnTitle:true });
fs.writeFile(path+'/'+'throughput.csv', csv, function(err) {
if (err) throw err;
console.log('file saved');
});
}
}
}
/**********************************************************************************************************/
// pcap2csv('/home/watch1/ayesh-server/Watch1CodeServer/pcaps','tcp');
module.exports = pcap2csv;