dns.Resolver 类
域名系统请求的独立解析器。
创建新的解析器使用默认的服务器设置。
使用 resolver.setServers()
设置用于解析器的服务器不会影响其他解析器:
const { Resolver } = require('node:dns');
const resolver = new Resolver();
resolver.setServers(['4.4.4.4']);
// 此请求将使用 4.4.4.4 的服务器,与全局设置无关。
resolver.resolve4('example.org', (err, addresses) => {
// ...
});
可以使用 node:dns
模块中的以下方法:
resolver.getServers()
resolver.resolve()
resolver.resolve4()
resolver.resolve6()
resolver.resolveAny()
resolver.resolveCaa()
resolver.resolveCname()
resolver.resolveMx()
resolver.resolveNaptr()
resolver.resolveNs()
resolver.resolvePtr()
resolver.resolveSoa()
resolver.resolveSrv()
resolver.resolveTxt()
resolver.reverse()
resolver.setServers()
An independent resolver for DNS requests.
Creating a new resolver uses the default server settings. Setting
the servers used for a resolver using
resolver.setServers()
does not affect
other resolvers:
const { Resolver } = require('node:dns');
const resolver = new Resolver();
resolver.setServers(['4.4.4.4']);
// This request will use the server at 4.4.4.4, independent of global settings.
resolver.resolve4('example.org', (err, addresses) => {
// ...
});
The following methods from the node:dns
module are available:
resolver.getServers()
resolver.resolve()
resolver.resolve4()
resolver.resolve6()
resolver.resolveAny()
resolver.resolveCaa()
resolver.resolveCname()
resolver.resolveMx()
resolver.resolveNaptr()
resolver.resolveNs()
resolver.resolvePtr()
resolver.resolveSoa()
resolver.resolveSrv()
resolver.resolveTxt()
resolver.reverse()
resolver.setServers()