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';
|
'use strict';
|
||||||
|
|
||||||
var cli = require('cli');
|
var cli = require('cli');
|
||||||
|
var dns = require('dns');
|
||||||
var dgram = require('dgram');
|
var dgram = require('dgram');
|
||||||
var dnsjs = require('dns-suite');
|
var dnsjs = require('dns-suite');
|
||||||
var hexdump = require('../hexdump');
|
var hexdump = require('../hexdump');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var common = require('../common');
|
var common = require('../common');
|
||||||
|
var defaultNameservers = require('dns').getServers();
|
||||||
|
|
||||||
cli.parse({
|
cli.parse({
|
||||||
// 'b': [ false, 'set source IP address (defaults to 0.0.0.0)', 'string' ]
|
// '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' ]
|
, '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' ]
|
, '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' ]
|
, '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' ]
|
//, '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' ]
|
, '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' ]
|
, '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.writeQuery(cli, query, queryAb);
|
||||||
//common.writeResponse(opts, query, nb, packet);
|
//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 () {
|
handlers.onListening = function () {
|
||||||
/*jshint validthis:true*/
|
/*jshint validthis:true*/
|
||||||
var server = this;
|
var server = this;
|
||||||
var nameserver = cli.nameserver;
|
var nameserver = cli.nameserver;
|
||||||
var nameservers;
|
|
||||||
var index;
|
var index;
|
||||||
|
|
||||||
if (!nameserver) {
|
if (!nameserver) {
|
||||||
nameservers = require('dns').getServers();
|
index = crypto.randomBytes(2).readUInt16BE(0) % defaultNameservers.length;
|
||||||
index = crypto.randomBytes(2).readUInt16BE(0) % nameservers.length;
|
nameserver = defaultNameservers[index];
|
||||||
nameserver = nameservers[index];
|
|
||||||
if (cli.debug) {
|
if (cli.debug) {
|
||||||
console.log(index, nameservers);
|
console.log(index, defaultNameservers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue