dns.resolve(hostname[, rrtype], callback)
hostname
<string> 要解析的主机名。rrtype
<string> 资源记录类型。 默认值:'A'
。callback
<Function>err
<Error>records
<string[]> | <Object[]> | <Object>
使用域名系统协议将主机名(例如 'nodejs.org'
)解析为资源记录数组。
callback
函数有参数 (err, records)
。
当成功时,records
将是资源记录数组。
个别结果的类型和结构因 rrtype
而异:
rrtype | records 包含 | 结果的类型 | 快捷方法 |
---|---|---|---|
'A' | IPv4 地址(默认) | <string> | dns.resolve4() |
'AAAA' | IPv6 地址 | <string> | dns.resolve6() |
'ANY' | 任何记录 | <Object> | dns.resolveAny() |
'CNAME' | 规范名称记录 | <string> | dns.resolveCname() |
'MX' | 邮件交换记录 | <Object> | dns.resolveMx() |
'NAPTR' | 名称授权指针记录 | <Object> | dns.resolveNaptr() |
'NS' | 名称服务器记录 | <string> | dns.resolveNs() |
'PTR' | 指针记录 | <string> | dns.resolvePtr() |
'SOA' | 起始规范记录 | <Object> | dns.resolveSoa() |
'SRV' | 服务记录 | <Object> | dns.resolveSrv() |
'TXT' | 文本记录 | <string[]> | dns.resolveTxt() |
hostname
<string> Host name to resolve.rrtype
<string> Resource record type. Default:'A'
.callback
<Function>err
<Error>records
<string[]> | <Object[]> | <Object>
Uses the DNS protocol to resolve a host name (e.g. 'nodejs.org'
) into an array
of the resource records. The callback
function has arguments
(err, records)
. When successful, records
will be an array of resource
records. The type and structure of individual results varies based on rrtype
:
rrtype | records contains | Result type | Shorthand method |
---|---|---|---|
'A' | IPv4 addresses (default) | <string> | dns.resolve4() |
'AAAA' | IPv6 addresses | <string> | dns.resolve6() |
'ANY' | any records | <Object> | dns.resolveAny() |
'CNAME' | canonical name records | <string> | dns.resolveCname() |
'MX' | mail exchange records | <Object> | dns.resolveMx() |
'NAPTR' | name authority pointer records | <Object> | dns.resolveNaptr() |
'NS' | name server records | <string> | dns.resolveNs() |
'PTR' | pointer records | <string> | dns.resolvePtr() |
'SOA' | start of authority records | <Object> | dns.resolveSoa() |
'SRV' | service records | <Object> | dns.resolveSrv() |
'TXT' | text records | <string[]> | dns.resolveTxt() |
On error, err
is an Error
object, where err.code
is one of the
DNS error codes.