dns-pack works for json files

This commit is contained in:
AJ ONeal 2017-09-26 15:58:38 -06:00
parent ab533ab36c
commit e9169d7ef1
1 changed files with 23 additions and 3 deletions

View File

@ -3,12 +3,22 @@
// EXAMPLE:
// node bin/dns-parse.js samples/a-0.mdns.bin
var path = require('path');
// pass a terminal arg
var filename = process.argv[2];
var outname = process.argv[3];
if (!filename) {
console.error("Usage: node bin/dns-pack.js <path/to/sample.json>");
console.error("Example: node bin/dns-pack.js ./samples/services-0.mdns.json");
console.error("Usage: node bin/dns-pack.js <path/to/sample.json> <path/to/output.bin>");
console.error("Example: node bin/dns-pack.js ./samples/services-0.mdns.json ./services-0.mdns.bin");
process.exit(1);
return;
}
if (!outname) {
console.warn('');
console.warn(
"Usage: node bin/dns-pack.js '" + filename + "' './" + path.basename(filename).replace(path.extname(filename), '') + ".bin'"
);
console.warn('');
}
@ -32,10 +42,20 @@ fs.readFileAsync(filename, null).then(function (nb) {
// nb.buffer is the actual ArrayBuffer
//var ab = nb.buffer.slice(nb.byteOffset, nb.byteOffset + nb.byteLength);
var packet = dnsjs.write(JSON.parse(buffer.toString('ascii')));
var packet = dnsjs.write(JSON.parse(nb.toString('ascii')));
//console.log('[packet]', nb.byteLength, 'bytes:');
//console.log(JSON.stringify(packet, null, 2));
//TODO hexdump packet
var hexdump = require('hexdump.js').hexdump;
var str = hexdump(packet);
console.log(str);
if (outname) {
fs.writeFileSync(outname, packet, null);
console.log('');
console.log("wrote '" + outname + "'");
}
});