UNPKG

29.7 kBTypeScriptView Raw
1/**
2 * The `dns` module enables name resolution. For example, use it to look up IP
3 * addresses of host names.
4 *
5 * Although named for the [Domain Name System (DNS)](https://en.wikipedia.org/wiki/Domain_Name_System), it does not always use the
6 * DNS protocol for lookups. {@link lookup} uses the operating system
7 * facilities to perform name resolution. It may not need to perform any network
8 * communication. To perform name resolution the way other applications on the same
9 * system do, use {@link lookup}.
10 *
11 * ```js
12 * const dns = require('dns');
13 *
14 * dns.lookup('example.org', (err, address, family) => {
15 * console.log('address: %j family: IPv%s', address, family);
16 * });
17 * // address: "93.184.216.34" family: IPv4
18 * ```
19 *
20 * All other functions in the `dns` module connect to an actual DNS server to
21 * perform name resolution. They will always use the network to perform DNS
22 * queries. These functions do not use the same set of configuration files used by {@link lookup} (e.g. `/etc/hosts`). Use these functions to always perform
23 * DNS queries, bypassing other name-resolution facilities.
24 *
25 * ```js
26 * const dns = require('dns');
27 *
28 * dns.resolve4('archive.org', (err, addresses) => {
29 * if (err) throw err;
30 *
31 * console.log(`addresses: ${JSON.stringify(addresses)}`);
32 *
33 * addresses.forEach((a) => {
34 * dns.reverse(a, (err, hostnames) => {
35 * if (err) {
36 * throw err;
37 * }
38 * console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);
39 * });
40 * });
41 * });
42 * ```
43 *
44 * See the `Implementation considerations section` for more information.
45 * @see [source](https://github.com/nodejs/node/blob/v17.0.0/lib/dns.js)
46 */
47declare module 'dns' {
48 import * as dnsPromises from 'node:dns/promises';
49 // Supported getaddrinfo flags.
50 export const ADDRCONFIG: number;
51 export const V4MAPPED: number;
52 /**
53 * If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as
54 * well as IPv4 mapped IPv6 addresses.
55 */
56 export const ALL: number;
57 export interface LookupOptions {
58 family?: number | undefined;
59 hints?: number | undefined;
60 all?: boolean | undefined;
61 /**
62 * @default true
63 */
64 verbatim?: boolean | undefined;
65 }
66 export interface LookupOneOptions extends LookupOptions {
67 all?: false | undefined;
68 }
69 export interface LookupAllOptions extends LookupOptions {
70 all: true;
71 }
72 export interface LookupAddress {
73 address: string;
74 family: number;
75 }
76 /**
77 * Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
78 * AAAA (IPv6) record. All `option` properties are optional. If `options` is an
79 * integer, then it must be `4` or `6` – if `options` is not provided, then IPv4
80 * and IPv6 addresses are both returned if found.
81 *
82 * With the `all` option set to `true`, the arguments for `callback` change to`(err, addresses)`, with `addresses` being an array of objects with the
83 * properties `address` and `family`.
84 *
85 * On error, `err` is an `Error` object, where `err.code` is the error code.
86 * Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
87 * the host name does not exist but also when the lookup fails in other ways
88 * such as no available file descriptors.
89 *
90 * `dns.lookup()` does not necessarily have anything to do with the DNS protocol.
91 * The implementation uses an operating system facility that can associate names
92 * with addresses, and vice versa. This implementation can have subtle but
93 * important consequences on the behavior of any Node.js program. Please take some
94 * time to consult the `Implementation considerations section` before using`dns.lookup()`.
95 *
96 * Example usage:
97 *
98 * ```js
99 * const dns = require('dns');
100 * const options = {
101 * family: 6,
102 * hints: dns.ADDRCONFIG | dns.V4MAPPED,
103 * };
104 * dns.lookup('example.com', options, (err, address, family) =>
105 * console.log('address: %j family: IPv%s', address, family));
106 * // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
107 *
108 * // When options.all is true, the result will be an Array.
109 * options.all = true;
110 * dns.lookup('example.com', options, (err, addresses) =>
111 * console.log('addresses: %j', addresses));
112 * // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
113 * ```
114 *
115 * If this method is invoked as its `util.promisify()` ed version, and `all`is not set to `true`, it returns a `Promise` for an `Object` with `address` and`family` properties.
116 * @since v0.1.90
117 */
118 export function lookup(hostname: string, family: number, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void): void;
119 export function lookup(hostname: string, options: LookupOneOptions, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void): void;
120 export function lookup(hostname: string, options: LookupAllOptions, callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void): void;
121 export function lookup(hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, address: string | LookupAddress[], family: number) => void): void;
122 export function lookup(hostname: string, callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void): void;
123 export namespace lookup {
124 function __promisify__(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>;
125 function __promisify__(hostname: string, options?: LookupOneOptions | number): Promise<LookupAddress>;
126 function __promisify__(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>;
127 }
128 /**
129 * Resolves the given `address` and `port` into a host name and service using
130 * the operating system's underlying `getnameinfo` implementation.
131 *
132 * If `address` is not a valid IP address, a `TypeError` will be thrown.
133 * The `port` will be coerced to a number. If it is not a legal port, a `TypeError`will be thrown.
134 *
135 * On an error, `err` is an `Error` object, where `err.code` is the error code.
136 *
137 * ```js
138 * const dns = require('dns');
139 * dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
140 * console.log(hostname, service);
141 * // Prints: localhost ssh
142 * });
143 * ```
144 *
145 * If this method is invoked as its `util.promisify()` ed version, it returns a`Promise` for an `Object` with `hostname` and `service` properties.
146 * @since v0.11.14
147 */
148 export function lookupService(address: string, port: number, callback: (err: NodeJS.ErrnoException | null, hostname: string, service: string) => void): void;
149 export namespace lookupService {
150 function __promisify__(
151 address: string,
152 port: number
153 ): Promise<{
154 hostname: string;
155 service: string;
156 }>;
157 }
158 export interface ResolveOptions {
159 ttl: boolean;
160 }
161 export interface ResolveWithTtlOptions extends ResolveOptions {
162 ttl: true;
163 }
164 export interface RecordWithTtl {
165 address: string;
166 ttl: number;
167 }
168 /** @deprecated Use `AnyARecord` or `AnyAaaaRecord` instead. */
169 export type AnyRecordWithTtl = AnyARecord | AnyAaaaRecord;
170 export interface AnyARecord extends RecordWithTtl {
171 type: 'A';
172 }
173 export interface AnyAaaaRecord extends RecordWithTtl {
174 type: 'AAAA';
175 }
176 export interface CaaRecord {
177 critial: number;
178 issue?: string | undefined;
179 issuewild?: string | undefined;
180 iodef?: string | undefined;
181 contactemail?: string | undefined;
182 contactphone?: string | undefined;
183 }
184 export interface MxRecord {
185 priority: number;
186 exchange: string;
187 }
188 export interface AnyMxRecord extends MxRecord {
189 type: 'MX';
190 }
191 export interface NaptrRecord {
192 flags: string;
193 service: string;
194 regexp: string;
195 replacement: string;
196 order: number;
197 preference: number;
198 }
199 export interface AnyNaptrRecord extends NaptrRecord {
200 type: 'NAPTR';
201 }
202 export interface SoaRecord {
203 nsname: string;
204 hostmaster: string;
205 serial: number;
206 refresh: number;
207 retry: number;
208 expire: number;
209 minttl: number;
210 }
211 export interface AnySoaRecord extends SoaRecord {
212 type: 'SOA';
213 }
214 export interface SrvRecord {
215 priority: number;
216 weight: number;
217 port: number;
218 name: string;
219 }
220 export interface AnySrvRecord extends SrvRecord {
221 type: 'SRV';
222 }
223 export interface AnyTxtRecord {
224 type: 'TXT';
225 entries: string[];
226 }
227 export interface AnyNsRecord {
228 type: 'NS';
229 value: string;
230 }
231 export interface AnyPtrRecord {
232 type: 'PTR';
233 value: string;
234 }
235 export interface AnyCnameRecord {
236 type: 'CNAME';
237 value: string;
238 }
239 export type AnyRecord = AnyARecord | AnyAaaaRecord | AnyCnameRecord | AnyMxRecord | AnyNaptrRecord | AnyNsRecord | AnyPtrRecord | AnySoaRecord | AnySrvRecord | AnyTxtRecord;
240 /**
241 * Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
242 * of the resource records. The `callback` function has arguments`(err, records)`. When successful, `records` will be an array of resource
243 * records. The type and structure of individual results varies based on `rrtype`:
244 *
245 * <omitted>
246 *
247 * On error, `err` is an `Error` object, where `err.code` is one of theDNS error codes.
248 * @since v0.1.27
249 * @param hostname Host name to resolve.
250 * @param [rrtype='A'] Resource record type.
251 */
252 export function resolve(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
253 export function resolve(hostname: string, rrtype: 'A', callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
254 export function resolve(hostname: string, rrtype: 'AAAA', callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
255 export function resolve(hostname: string, rrtype: 'ANY', callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void): void;
256 export function resolve(hostname: string, rrtype: 'CNAME', callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
257 export function resolve(hostname: string, rrtype: 'MX', callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void): void;
258 export function resolve(hostname: string, rrtype: 'NAPTR', callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void): void;
259 export function resolve(hostname: string, rrtype: 'NS', callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
260 export function resolve(hostname: string, rrtype: 'PTR', callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
261 export function resolve(hostname: string, rrtype: 'SOA', callback: (err: NodeJS.ErrnoException | null, addresses: SoaRecord) => void): void;
262 export function resolve(hostname: string, rrtype: 'SRV', callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void): void;
263 export function resolve(hostname: string, rrtype: 'TXT', callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void): void;
264 export function resolve(
265 hostname: string,
266 rrtype: string,
267 callback: (err: NodeJS.ErrnoException | null, addresses: string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | string[][] | AnyRecord[]) => void
268 ): void;
269 export namespace resolve {
270 function __promisify__(hostname: string, rrtype?: 'A' | 'AAAA' | 'CNAME' | 'NS' | 'PTR'): Promise<string[]>;
271 function __promisify__(hostname: string, rrtype: 'ANY'): Promise<AnyRecord[]>;
272 function __promisify__(hostname: string, rrtype: 'MX'): Promise<MxRecord[]>;
273 function __promisify__(hostname: string, rrtype: 'NAPTR'): Promise<NaptrRecord[]>;
274 function __promisify__(hostname: string, rrtype: 'SOA'): Promise<SoaRecord>;
275 function __promisify__(hostname: string, rrtype: 'SRV'): Promise<SrvRecord[]>;
276 function __promisify__(hostname: string, rrtype: 'TXT'): Promise<string[][]>;
277 function __promisify__(hostname: string, rrtype: string): Promise<string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | string[][] | AnyRecord[]>;
278 }
279 /**
280 * Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the`hostname`. The `addresses` argument passed to the `callback` function
281 * will contain an array of IPv4 addresses (e.g.`['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
282 * @since v0.1.16
283 * @param hostname Host name to resolve.
284 */
285 export function resolve4(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
286 export function resolve4(hostname: string, options: ResolveWithTtlOptions, callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void): void;
287 export function resolve4(hostname: string, options: ResolveOptions, callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void): void;
288 export namespace resolve4 {
289 function __promisify__(hostname: string): Promise<string[]>;
290 function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
291 function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
292 }
293 /**
294 * Uses the DNS protocol to resolve a IPv6 addresses (`AAAA` records) for the`hostname`. The `addresses` argument passed to the `callback` function
295 * will contain an array of IPv6 addresses.
296 * @since v0.1.16
297 * @param hostname Host name to resolve.
298 */
299 export function resolve6(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
300 export function resolve6(hostname: string, options: ResolveWithTtlOptions, callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void): void;
301 export function resolve6(hostname: string, options: ResolveOptions, callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void): void;
302 export namespace resolve6 {
303 function __promisify__(hostname: string): Promise<string[]>;
304 function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
305 function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
306 }
307 /**
308 * Uses the DNS protocol to resolve `CNAME` records for the `hostname`. The`addresses` argument passed to the `callback` function
309 * will contain an array of canonical name records available for the `hostname`(e.g. `['bar.example.com']`).
310 * @since v0.3.2
311 */
312 export function resolveCname(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
313 export namespace resolveCname {
314 function __promisify__(hostname: string): Promise<string[]>;
315 }
316 /**
317 * Uses the DNS protocol to resolve `CAA` records for the `hostname`. The`addresses` argument passed to the `callback` function
318 * will contain an array of certification authority authorization records
319 * available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]`).
320 * @since v15.0.0, v14.17.0
321 */
322 export function resolveCaa(hostname: string, callback: (err: NodeJS.ErrnoException | null, records: CaaRecord[]) => void): void;
323 export namespace resolveCaa {
324 function __promisify__(hostname: string): Promise<CaaRecord[]>;
325 }
326 /**
327 * Uses the DNS protocol to resolve mail exchange records (`MX` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
328 * contain an array of objects containing both a `priority` and `exchange`property (e.g. `[{priority: 10, exchange: 'mx.example.com'}, ...]`).
329 * @since v0.1.27
330 */
331 export function resolveMx(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void): void;
332 export namespace resolveMx {
333 function __promisify__(hostname: string): Promise<MxRecord[]>;
334 }
335 /**
336 * Uses the DNS protocol to resolve regular expression based records (`NAPTR`records) for the `hostname`. The `addresses` argument passed to the `callback`function will contain an array of
337 * objects with the following properties:
338 *
339 * * `flags`
340 * * `service`
341 * * `regexp`
342 * * `replacement`
343 * * `order`
344 * * `preference`
345 *
346 * ```js
347 * {
348 * flags: 's',
349 * service: 'SIP+D2U',
350 * regexp: '',
351 * replacement: '_sip._udp.example.com',
352 * order: 30,
353 * preference: 100
354 * }
355 * ```
356 * @since v0.9.12
357 */
358 export function resolveNaptr(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void): void;
359 export namespace resolveNaptr {
360 function __promisify__(hostname: string): Promise<NaptrRecord[]>;
361 }
362 /**
363 * Uses the DNS protocol to resolve name server records (`NS` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
364 * contain an array of name server records available for `hostname`(e.g. `['ns1.example.com', 'ns2.example.com']`).
365 * @since v0.1.90
366 */
367 export function resolveNs(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
368 export namespace resolveNs {
369 function __promisify__(hostname: string): Promise<string[]>;
370 }
371 /**
372 * Uses the DNS protocol to resolve pointer records (`PTR` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
373 * be an array of strings containing the reply records.
374 * @since v6.0.0
375 */
376 export function resolvePtr(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void): void;
377 export namespace resolvePtr {
378 function __promisify__(hostname: string): Promise<string[]>;
379 }
380 /**
381 * Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
382 * the `hostname`. The `address` argument passed to the `callback` function will
383 * be an object with the following properties:
384 *
385 * * `nsname`
386 * * `hostmaster`
387 * * `serial`
388 * * `refresh`
389 * * `retry`
390 * * `expire`
391 * * `minttl`
392 *
393 * ```js
394 * {
395 * nsname: 'ns.example.com',
396 * hostmaster: 'root.example.com',
397 * serial: 2013101809,
398 * refresh: 10000,
399 * retry: 2400,
400 * expire: 604800,
401 * minttl: 3600
402 * }
403 * ```
404 * @since v0.11.10
405 */
406 export function resolveSoa(hostname: string, callback: (err: NodeJS.ErrnoException | null, address: SoaRecord) => void): void;
407 export namespace resolveSoa {
408 function __promisify__(hostname: string): Promise<SoaRecord>;
409 }
410 /**
411 * Uses the DNS protocol to resolve service records (`SRV` records) for the`hostname`. The `addresses` argument passed to the `callback` function will
412 * be an array of objects with the following properties:
413 *
414 * * `priority`
415 * * `weight`
416 * * `port`
417 * * `name`
418 *
419 * ```js
420 * {
421 * priority: 10,
422 * weight: 5,
423 * port: 21223,
424 * name: 'service.example.com'
425 * }
426 * ```
427 * @since v0.1.27
428 */
429 export function resolveSrv(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void): void;
430 export namespace resolveSrv {
431 function __promisify__(hostname: string): Promise<SrvRecord[]>;
432 }
433 /**
434 * Uses the DNS protocol to resolve text queries (`TXT` records) for the`hostname`. The `records` argument passed to the `callback` function is a
435 * two-dimensional array of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
436 * one record. Depending on the use case, these could be either joined together or
437 * treated separately.
438 * @since v0.1.27
439 */
440 export function resolveTxt(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void): void;
441 export namespace resolveTxt {
442 function __promisify__(hostname: string): Promise<string[][]>;
443 }
444 /**
445 * Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
446 * The `ret` argument passed to the `callback` function will be an array containing
447 * various types of records. Each object has a property `type` that indicates the
448 * type of the current record. And depending on the `type`, additional properties
449 * will be present on the object:
450 *
451 * <omitted>
452 *
453 * Here is an example of the `ret` object passed to the callback:
454 *
455 * ```js
456 * [ { type: 'A', address: '127.0.0.1', ttl: 299 },
457 * { type: 'CNAME', value: 'example.com' },
458 * { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
459 * { type: 'NS', value: 'ns1.example.com' },
460 * { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
461 * { type: 'SOA',
462 * nsname: 'ns1.example.com',
463 * hostmaster: 'admin.example.com',
464 * serial: 156696742,
465 * refresh: 900,
466 * retry: 900,
467 * expire: 1800,
468 * minttl: 60 } ]
469 * ```
470 *
471 * DNS server operators may choose not to respond to `ANY`queries. It may be better to call individual methods like {@link resolve4},{@link resolveMx}, and so on. For more details, see [RFC
472 * 8482](https://tools.ietf.org/html/rfc8482).
473 */
474 export function resolveAny(hostname: string, callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void): void;
475 export namespace resolveAny {
476 function __promisify__(hostname: string): Promise<AnyRecord[]>;
477 }
478 /**
479 * Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
480 * array of host names.
481 *
482 * On error, `err` is an `Error` object, where `err.code` is
483 * one of the `DNS error codes`.
484 * @since v0.1.16
485 */
486 export function reverse(ip: string, callback: (err: NodeJS.ErrnoException | null, hostnames: string[]) => void): void;
487 /**
488 * Sets the IP address and port of servers to be used when performing DNS
489 * resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
490 * addresses. If the port is the IANA default DNS port (53) it can be omitted.
491 *
492 * ```js
493 * dns.setServers([
494 * '4.4.4.4',
495 * '[2001:4860:4860::8888]',
496 * '4.4.4.4:1053',
497 * '[2001:4860:4860::8888]:1053',
498 * ]);
499 * ```
500 *
501 * An error will be thrown if an invalid address is provided.
502 *
503 * The `dns.setServers()` method must not be called while a DNS query is in
504 * progress.
505 *
506 * The {@link setServers} method affects only {@link resolve},`dns.resolve*()` and {@link reverse} (and specifically _not_ {@link lookup}).
507 *
508 * This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
509 * That is, if attempting to resolve with the first server provided results in a`NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with
510 * subsequent servers provided. Fallback DNS servers will only be used if the
511 * earlier ones time out or result in some other error.
512 * @since v0.11.3
513 * @param servers array of `RFC 5952` formatted addresses
514 */
515 export function setServers(servers: ReadonlyArray<string>): void;
516 /**
517 * Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
518 * that are currently configured for DNS resolution. A string will include a port
519 * section if a custom port is used.
520 *
521 * ```js
522 * [
523 * '4.4.4.4',
524 * '2001:4860:4860::8888',
525 * '4.4.4.4:1053',
526 * '[2001:4860:4860::8888]:1053',
527 * ]
528 * ```
529 * @since v0.11.3
530 */
531 export function getServers(): string[];
532 /**
533 * Set the default value of `verbatim` in {@link lookup} and `dnsPromises.lookup()`. The value could be:
534 *
535 * * `ipv4first`: sets default `verbatim` `false`.
536 * * `verbatim`: sets default `verbatim` `true`.
537 *
538 * The default is `ipv4first` and {@link setDefaultResultOrder} have higher
539 * priority than `--dns-result-order`. When using `worker threads`,{@link setDefaultResultOrder} from the main thread won't affect the default
540 * dns orders in workers.
541 * @since v16.4.0, v14.18.0
542 * @param order must be `'ipv4first'` or `'verbatim'`.
543 */
544 export function setDefaultResultOrder(order: 'ipv4first' | 'verbatim'): void;
545 // Error codes
546 export const NODATA: string;
547 export const FORMERR: string;
548 export const SERVFAIL: string;
549 export const NOTFOUND: string;
550 export const NOTIMP: string;
551 export const REFUSED: string;
552 export const BADQUERY: string;
553 export const BADNAME: string;
554 export const BADFAMILY: string;
555 export const BADRESP: string;
556 export const CONNREFUSED: string;
557 export const TIMEOUT: string;
558 export const EOF: string;
559 export const FILE: string;
560 export const NOMEM: string;
561 export const DESTRUCTION: string;
562 export const BADSTR: string;
563 export const BADFLAGS: string;
564 export const NONAME: string;
565 export const BADHINTS: string;
566 export const NOTINITIALIZED: string;
567 export const LOADIPHLPAPI: string;
568 export const ADDRGETNETWORKPARAMS: string;
569 export const CANCELLED: string;
570 export interface ResolverOptions {
571 timeout?: number | undefined;
572 /**
573 * @default 4
574 */
575 tries?: number;
576 }
577 /**
578 * An independent resolver for DNS requests.
579 *
580 * Creating a new resolver uses the default server settings. Setting
581 * the servers used for a resolver using `resolver.setServers()` does not affect
582 * other resolvers:
583 *
584 * ```js
585 * const { Resolver } = require('dns');
586 * const resolver = new Resolver();
587 * resolver.setServers(['4.4.4.4']);
588 *
589 * // This request will use the server at 4.4.4.4, independent of global settings.
590 * resolver.resolve4('example.org', (err, addresses) => {
591 * // ...
592 * });
593 * ```
594 *
595 * The following methods from the `dns` module are available:
596 *
597 * * `resolver.getServers()`
598 * * `resolver.resolve()`
599 * * `resolver.resolve4()`
600 * * `resolver.resolve6()`
601 * * `resolver.resolveAny()`
602 * * `resolver.resolveCaa()`
603 * * `resolver.resolveCname()`
604 * * `resolver.resolveMx()`
605 * * `resolver.resolveNaptr()`
606 * * `resolver.resolveNs()`
607 * * `resolver.resolvePtr()`
608 * * `resolver.resolveSoa()`
609 * * `resolver.resolveSrv()`
610 * * `resolver.resolveTxt()`
611 * * `resolver.reverse()`
612 * * `resolver.setServers()`
613 * @since v8.3.0
614 */
615 export class Resolver {
616 constructor(options?: ResolverOptions);
617 /**
618 * Cancel all outstanding DNS queries made by this resolver. The corresponding
619 * callbacks will be called with an error with code `ECANCELLED`.
620 * @since v8.3.0
621 */
622 cancel(): void;
623 getServers: typeof getServers;
624 resolve: typeof resolve;
625 resolve4: typeof resolve4;
626 resolve6: typeof resolve6;
627 resolveAny: typeof resolveAny;
628 resolveCname: typeof resolveCname;
629 resolveMx: typeof resolveMx;
630 resolveNaptr: typeof resolveNaptr;
631 resolveNs: typeof resolveNs;
632 resolvePtr: typeof resolvePtr;
633 resolveSoa: typeof resolveSoa;
634 resolveSrv: typeof resolveSrv;
635 resolveTxt: typeof resolveTxt;
636 reverse: typeof reverse;
637 /**
638 * The resolver instance will send its requests from the specified IP address.
639 * This allows programs to specify outbound interfaces when used on multi-homed
640 * systems.
641 *
642 * If a v4 or v6 address is not specified, it is set to the default, and the
643 * operating system will choose a local address automatically.
644 *
645 * The resolver will use the v4 local address when making requests to IPv4 DNS
646 * servers, and the v6 local address when making requests to IPv6 DNS servers.
647 * The `rrtype` of resolution requests has no impact on the local address used.
648 * @since v15.1.0, v14.17.0
649 * @param [ipv4='0.0.0.0'] A string representation of an IPv4 address.
650 * @param [ipv6='::0'] A string representation of an IPv6 address.
651 */
652 setLocalAddress(ipv4?: string, ipv6?: string): void;
653 setServers: typeof setServers;
654 }
655 export { dnsPromises as promises };
656}
657declare module 'node:dns' {
658 export * from 'dns';
659}