diff --git a/README.md b/README.md index 1273266..ad0d344 100644 --- a/README.md +++ b/README.md @@ -77,4 +77,6 @@ Options -c default IN -p default 53 (mdns default: 5353) (listener is random for DNS and 5353 for mDNS) -q (superfluous) required (ex: daplie.com) + ++time= Sets the timeout for a query in seconds. ``` diff --git a/bin/dig.js b/bin/dig.js index 20305d0..97a9d7a 100755 --- a/bin/dig.js +++ b/bin/dig.js @@ -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,7 +258,15 @@ function request(query, opts) { // 0 dns request // 53 dns server // 5353 mdns - server.bind(0); + if (opts.mdns) { + server.bind(5353); + setTimeout(function () { + server.close(); + }, opts.timeout || (5 * 1000)); + } + else { + server.bind(0); + } } cli.main(function (args, cli) { @@ -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) {