Node.js – dnsPromises.resolveAny() 方法


dnsPromises.resolveAny() 方法使用 DNS 协议解析所有记录(也称为ANY* 查询)。该 promise 使用包含各种类型记录的数组进行解析。

类型属性
'A'IPv4 地址
'AAAA'IPv6 地址
'Any'任何记录
MX邮件交换记录
NAPTR名称授权指针记录
NS名称服务器记录
PTR指针记录
SOA授权记录开始
SRV服务记录
TXT文本记录
CNAME规范名称记录

语法

dnsPromises.resolveAny(hostname)

参数

  • hostname - 此参数获取要解析的主机的输入。

示例 1

使用名称“resolveAny.js”创建一个文件,然后复制以下代码。创建文件后,使用命令“node resolveAny.js”运行此代码,如下例所示 −

// Node.js program to demonstrate the
// dnsPromises.resolveAny() method

// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;

// Calling dnsPromises.resolveAny() method
dnsPromises.resolveAny('tutorialspoint.com').then((response) => { 
   console.log("records :", response);
});

输出

C:\home
ode>> node resolveAny.js records: [ {"address":"95.217.74.146","ttl":600,"type":"A"}, {"exchange":"alt2.aspmx.l.google.com","priority":5,"type":"MX"}, {"exchange":"alt1.aspmx.l.google.com","priority":5,"type":"MX"}, {"exchange":"aspmx.l.google.com","priority":1,"type":"MX"}, {"exchange":"alt4.aspmx.l.google.com","priority":10,"type":"MX"}, {"exchange":"alt3.aspmx.l.google.com","priority":10,"type":"MX"}, {"value":"pdns13.domaincontrol.com","type":"NS"}, {"value":"pdns14.domaincontrol.com","type":"NS"}, {"entries":["google-site-verification=-RNrP1jBNMarh7tMQEgXtlBVUi000DUph-h8H7uSaQ"],"type":"TXT"}, {"entries":["google-siteverification=S2zMIBQyc6WxHPiOdUzkWYvx_FKbf03xDOsI8OgG20A"],"type" :"TXT"}, {"entries":["v=spf1 ip4:116.202.79.150 include:_spf.google.com - all"],"type":"TXT"}, {"nsname":"pdns13.domaincontrol.com","hostmaster":"dns.jomax.net" ,"serial":2021051700,"refresh":28800,"retry":7200,"expire":604800 ,"minttl":600,"type":"SOA"} ]

示例 2

// Node.js program to demonstrate the
// dnsPromises.resolveAny() method

// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;

// Calling dnsPromises.resolveAny() method
dnsPromises.resolveAny('localhost').then((response) => {
   console.log("Address :", response);
});

输出

C:\home
ode>> node resolveAny.js Address : [ { address: '127.0.0.1', ttl: 0, type: 'A' }, { address: '::1', ttl: 0, type: 'AAAA' } ]

更新于: 2021-11-24

154 次浏览

开启您的职业生涯

完成课程获取认证

开始
广告