dns.resolve(hostname[, rrtype], callback)


  • hostname <string> 要解析的主机名。
  • rrtype <string> 资源记录类型。默认值: 'A'
  • callback <Function>
    • err <Error>
    • records 字符串数组 | 对象数组 | 对象

使用 DNS 协议将主机名(例如 'nodejs.org')解析为资源记录数组。callback 函数的参数为 (err, records)。成功时,records 将是一个资源记录数组。单个结果的类型和结构取决于 rrtype

【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:】

rrtyperecords containsResult typeShorthand method
'A'IPv4 addresses (default)<string>dns.resolve4()
'AAAA'IPv6 addresses<string>dns.resolve6()
'ANY'any records<Object>dns.resolveAny()
'CAA'CA authorization records<Object>dns.resolveCaa()
'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()
'TLSA'certificate associations<Object>dns.resolveTlsa()
'TXT'text records<string[]>dns.resolveTxt()

出现错误时,err 是一个 Error 对象,其中 err.codeDNS 错误代码 之一。

【On error, err is an Error object, where err.code is one of the DNS error codes.】