-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
executable file
路60 lines (52 loc) 路 1.7 KB
/
Copy pathapp.js
File metadata and controls
executable file
路60 lines (52 loc) 路 1.7 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
#!/usr/bin/env node
const program = require('commander');
const convert = require('./sanitize');
const ipaddr = require('ipaddr.js');
const execa = require('execa');
const fs = require('fs');
function collect(val, memo) {
if (ipaddr.isValid(val)) {
val = ipaddr.parse(val);
val = [val, val.kind() == 'ipv6' ? 128 : 32];
} else {
val = ipaddr.parseCIDR(val);
}
memo.push(val);
return memo;
}
program
// .version('0.0.0')
.option('-r, --redact [ip]', 'IP, CIDR or subnet to redact', collect, [])
.option('-p, --redact-private', 'redact all subnets assigned for private use')
.option('-m, --redact-mac', 'randomize ethernet hardware MAC addresses')
.option('-a, --append', 'Append to existing pcap if [file] exists')
.option('-o, --out [file]', 'Specify a single output file', '-')
.parse(process.argv);
async function run () {
var opts = {};
opts.private_ranges = program.redact;
opts.private = !!program.redactPrivate;
opts.mac = !!program.redactMac;
var files = program.args;
var writeStream;
if (program.out !== undefined && program.out !== '-')
writeStream = fs.createWriteStream(program.out);
else if (!process.stdout.isTTY)
writeStream = process.stdout;
else {
console.error('no output file given');
process.exit(1);
}
for (let f of files)
await sani(f, writeStream, opts);
//files.forEach(f => sani(f, writeStream, opts));
//writeStream.end();
}
async function sani (capfile, writeStream, opts = {}) {
// jsonraw has no timestamps
//var proc = execa.shell(`tshark -r ${capfile} -T jsonraw`);
var proc = execa.shell(`tshark -r ${capfile} -T json -x`);
// FIXME: This doesn't wait
await convert(proc.stdout, writeStream, opts);
}
run();