Skip to content

Commit 30bc9dc

Browse files
XadillaXaddaleax
authored andcommitted
dns: add resolveAny support
`dns.resolveAny` and `dns.resolve` with `"ANY"` has the similar behavior like `$ dig <domain> any` and returns an array with several types of records. `dns.resolveAny` parses the result packet by several rules in turn. Supported types: * A * AAAA * CNAME * MX * NAPTR * NS * PTR * SOA * SRV * TXT Fixes: #2848 PR-URL: #13137 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent cb9adcc commit 30bc9dc

File tree

5 files changed

+975
-174
lines changed

5 files changed

+975
-174
lines changed

doc/api/dns.md

+47
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ records. The type and structure of individual results varies based on `rrtype`:
210210
| `'SOA'` | start of authority records | {Object} | [`dns.resolveSoa()`][] |
211211
| `'SRV'` | service records | {Object} | [`dns.resolveSrv()`][] |
212212
| `'TXT'` | text records | {string} | [`dns.resolveTxt()`][] |
213+
| `'ANY'` | any records | {Object} | [`dns.resolveAny()`][] |
213214

214215
On error, `err` is an [`Error`][] object, where `err.code` is one of the
215216
[DNS error codes](#dns_error_codes).
@@ -430,6 +431,51 @@ is a two-dimensional array of the text records available for `hostname` (e.g.,
430431
one record. Depending on the use case, these could be either joined together or
431432
treated separately.
432433

434+
## dns.resolveAny(hostname, callback)
435+
436+
- `hostname` {string}
437+
- `callback` {Function}
438+
- `err` {Error}
439+
- `ret` {Object[][]}
440+
441+
Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
442+
The `ret` argument passed to the `callback` function will be an array containing
443+
various types of records. Each object has a property `type` that indicates the
444+
type of the current record. And depending on the `type`, additional properties
445+
will be present on the object:
446+
447+
| Type | Properties |
448+
|------|------------|
449+
| `"A"` | `address` / `ttl` |
450+
| `"AAAA"` | `address` / `ttl` |
451+
| `"CNAME"` | `value` |
452+
| `"MX"` | Refer to [`dns.resolveMx()`][] |
453+
| `"NAPTR"` | Refer to [`dns.resolveNaptr()`][] |
454+
| `"NS"` | `value` |
455+
| `"PTR"` | `value` |
456+
| `"SOA"` | Refer to [`dns.resolveSoa()`][] |
457+
| `"SRV"` | Refer to [`dns.resolveSrv()`][] |
458+
| `"TXT"` | This type of record contains an array property called `entries` which refers to [`dns.resolveTxt()`][], eg. `{ entries: ['...'], type: 'TXT' }` |
459+
460+
Here is a example of the `ret` object passed to the callback:
461+
462+
<!-- eslint-disable -->
463+
```js
464+
[ { type: 'A', address: '127.0.0.1', ttl: 299 },
465+
{ type: 'CNAME', value: 'example.com' },
466+
{ type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
467+
{ type: 'NS', value: 'ns1.example.com', type: 'NS' },
468+
{ type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
469+
{ type: 'SOA',
470+
nsname: 'ns1.example.com',
471+
hostmaster: 'admin.example.com',
472+
serial: 156696742,
473+
refresh: 900,
474+
retry: 900,
475+
expire: 1800,
476+
minttl: 60 } ]
477+
```
478+
433479
## dns.reverse(ip, callback)
434480
<!-- YAML
435481
added: v0.1.16
@@ -554,6 +600,7 @@ uses. For instance, _they do not use the configuration from `/etc/hosts`_.
554600
[`dns.resolveSoa()`]: #dns_dns_resolvesoa_hostname_callback
555601
[`dns.resolveSrv()`]: #dns_dns_resolvesrv_hostname_callback
556602
[`dns.resolveTxt()`]: #dns_dns_resolvetxt_hostname_callback
603+
[`dns.resolveAny()`]: #dns_dns_resolveany_hostname_callback
557604
[DNS error codes]: #dns_error_codes
558605
[Implementation considerations section]: #dns_implementation_considerations
559606
[supported `getaddrinfo` flags]: #dns_supported_getaddrinfo_flags

lib/dns.js

+2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ function resolver(bindingName) {
269269

270270

271271
var resolveMap = Object.create(null);
272+
resolveMap.ANY = resolver('queryAny');
272273
resolveMap.A = resolver('queryA');
273274
resolveMap.AAAA = resolver('queryAaaa');
274275
resolveMap.CNAME = resolver('queryCname');
@@ -364,6 +365,7 @@ module.exports = {
364365
getServers,
365366
setServers,
366367
resolve,
368+
resolveAny: resolveMap.ANY,
367369
resolve4: resolveMap.A,
368370
resolve6: resolveMap.AAAA,
369371
resolveCname: resolveMap.CNAME,

0 commit comments

Comments
 (0)