Node.js – dnsPromises.resolveAny() 方法
该方法使用DNS协议来解析所有记录(这也称为ANY或*query)。承诺是通过一个包含各种类型记录的数组来解决的。dnsPromises.resolveAny()
语法
dnsPromises.resolveAny(hostname)
参数
主机名-此参数接受要解析的主机名的输入。
示例1
创建一个名为“resolveAny.js”的文件并复制以下代码。创建文件后,使用命令“noderesolveAny.js”运行此代码,如下例所示-
//Node.js程序来演示 //dnsPromises.resolveAny()方法 //从dns模块访问promises对象 const dns = require('dns'); const dnsPromises = dns.promises; //调用dnsPromises.resolveAny()方法 dnsPromises.resolveAny('nhooo.com').then((response) => { console.log("记录:", response); });输出结果
C:\home\node>> 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程序来演示 //dnsPromises.resolveAny()方法 //从dns模块访问promises对象 const dns = require('dns'); const dnsPromises = dns.promises; //调用dnsPromises.resolveAny()方法 dnsPromises.resolveAny('localhost').then((response) => { console.log("地址:", response); });输出结果
C:\home\node>> node resolveAny.js 地址: [ { address: '127.0.0.1', ttl: 0, type: 'A' }, { address: '::1', ttl: 0, type: 'AAAA' } ]