capture some dns packets

This commit is contained in:
AJ ONeal 2017-01-21 03:16:08 -07:00
parent d5a36adeec
commit 23beebf751
1 changed files with 4 additions and 11 deletions

View File

@ -1,7 +1,7 @@
'use strict';
// pass a terminal arg
var type = process.argv[2] || 'unknown';
var type = process.argv[2];
var count = parseInt(process.argv[3]) || 0;
if (!type) {
console.error("Usage: node aj-listener.js <type> [count]");
@ -24,15 +24,8 @@ handlers.onError = function (err) {
server.close();
};
handlers.onMessage = function (buffer) {
var name;
if (!count) {
name = type + '-' + count + '.mdns.bin';
}
else {
// probably the same device name responding
name = type + '-' + buffer.length + '.mdns.bin';
}
var name = type + '-' + count + '.mdns.bin';
count += 1;
fs.writeFileAsync(name, buffer).then(function () {
console.log('wrote ' + buffer.length + ' bytes to ' + name);
@ -54,4 +47,4 @@ server.on('listening', handlers.onListening);
// 53 dns
// 5353 mdns
server.bind(5353);
server.bind(5353);