This commit is contained in:
AJ ONeal 2017-02-23 17:31:09 -07:00
parent 50cfa7d8a6
commit b89789f631
2 changed files with 24 additions and 1 deletions

View File

@ -77,4 +77,6 @@ Options
-c <class> default IN
-p <port> default 53 (mdns default: 5353) (listener is random for DNS and 5353 for mDNS)
-q <query> (superfluous) required (ex: daplie.com)
+time=<seconds> Sets the timeout for a query in seconds.
```

View File

@ -12,6 +12,7 @@ cli.parse({
//, 'json': [ false, 'output results as json', 'string' ]
//, 'lint': [ false, 'attack (in the metaphorical sense) a nameserver with all sorts of queries to test for correct responses', 'string', false ]
, 'mdns': [ false, "Alias for setting defaults to -p 5353 @224.0.0.251 -t PTR -q _services._dns-sd._udp.local and waiting for multiple responses", 'boolean', false ]
, 'timeout': [ false, "Alias for setting defaults to -p 5353 @224.0.0.251 -t PTR -q _services._dns-sd._udp.local and waiting for multiple responses", 'boolean', false ]
, 'output': [ 'o', 'output prefix to use for writing query and response(s) to disk', 'file' ]
, 'port': [ 'p', 'port (defaults to 53 for dns and 5353 for mdns)', 'int' ]
//, 'serve': [ 's', 'path to json file with array of responses to issue for given queries', 'string' ]
@ -257,8 +258,16 @@ function request(query, opts) {
// 0 dns request
// 53 dns server
// 5353 mdns
if (opts.mdns) {
server.bind(5353);
setTimeout(function () {
server.close();
}, opts.timeout || (5 * 1000));
}
else {
server.bind(0);
}
}
cli.main(function (args, cli) {
args.forEach(function (arg) {
@ -271,6 +280,15 @@ cli.main(function (args, cli) {
cli.type = cli.t = arg.toUpperCase();
}
if (/^\+time=/.test(arg)) {
if (cli.timeout) {
console.error("'+time=' was specified more than once");
process.exit(1);
return;
}
cli.timeout = Math.round(parseInt(arg.replace(/\+time=/, ''), 10) * 1000);
}
if (/^@/.test(arg)) {
if (cli.nameserver) {
console.error("'@server' was specified more than once");
@ -299,6 +317,9 @@ cli.main(function (args, cli) {
if (!cli.nameserver) {
cli.nameserver = '224.0.0.251';
}
if (!cli.query) {
cli.query = '_services._dns-sd._udp.local';
}
}
if (!cli.type) {