WIP recursively resolve
This commit is contained in:
parent
36d7aaccbb
commit
03e3e527dc
24
bin/digd.js
24
bin/digd.js
|
@ -1,11 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
var cli = require('cli');
|
||||
var dns = require('dns');
|
||||
var dgram = require('dgram');
|
||||
var dnsjs = require('dns-suite');
|
||||
var hexdump = require('../hexdump');
|
||||
var crypto = require('crypto');
|
||||
var common = require('../common');
|
||||
var defaultNameservers = require('dns').getServers();
|
||||
|
||||
cli.parse({
|
||||
// 'b': [ false, 'set source IP address (defaults to 0.0.0.0)', 'string' ]
|
||||
|
@ -21,6 +23,7 @@ cli.parse({
|
|||
, 'output': [ 'o', 'output prefix to use for writing query and response(s) to disk', 'file' ]
|
||||
, 'address': [ false, 'ip address(es) to listen on (defaults to 0.0.0.0,::0)', 'string' ]
|
||||
, 'port': [ 'p', 'port (defaults to 53 for dns and 5353 for mdns)', 'int' ]
|
||||
, 'nameserver': [ false, 'the nameserver(s) to use for recursive lookups (defaults to ' + defaultNameservers.join(',') + ')', 'string' ]
|
||||
//, 'serve': [ 's', 'path to json file with array of responses to issue for given queries', 'string' ]
|
||||
, 'type': [ 't', 'type (defaults to ANY for dns and PTR for mdns)', 'string' ]
|
||||
, 'query': [ 'q', 'a superfluous explicit option to set the query as a command line flag' ]
|
||||
|
@ -128,20 +131,31 @@ cli.main(function (args, cli) {
|
|||
common.writeQuery(cli, query, queryAb);
|
||||
//common.writeResponse(opts, query, nb, packet);
|
||||
}
|
||||
|
||||
if (!cli.norecurse) {
|
||||
// ANY, A, AAAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, TXT
|
||||
var count = query.question.length;
|
||||
query.question.forEach(function (q) {
|
||||
dns.resolve(q.name, q.typeName, function () {
|
||||
count -= 1;
|
||||
if (!count) {
|
||||
}
|
||||
});
|
||||
console.log(';' + q.name + '.', ' ', q.className, q.typeName);
|
||||
});
|
||||
}
|
||||
};
|
||||
handlers.onListening = function () {
|
||||
/*jshint validthis:true*/
|
||||
var server = this;
|
||||
var nameserver = cli.nameserver;
|
||||
var nameservers;
|
||||
var index;
|
||||
|
||||
if (!nameserver) {
|
||||
nameservers = require('dns').getServers();
|
||||
index = crypto.randomBytes(2).readUInt16BE(0) % nameservers.length;
|
||||
nameserver = nameservers[index];
|
||||
index = crypto.randomBytes(2).readUInt16BE(0) % defaultNameservers.length;
|
||||
nameserver = defaultNameservers[index];
|
||||
if (cli.debug) {
|
||||
console.log(index, nameservers);
|
||||
console.log(index, defaultNameservers);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue