Node.js – dnsPromises.resolveTxt() 方法
dnsPromises.resolveTxt() 方法使用 DNS 协议解析主机名的文本搜索(TXT 记录)。如果成功,将使用可用主机名文本记录的二维数组解析该承诺。
语法
dnsPromises.resolveTxt(hostname)
参数
它只接受一个参数
hostname – 此参数作为要解析的主机名输入。
示例 1
创建一个名为 "resolveTxt.js" 的文件,并复制以下代码段。创建文件后,使用命令 "node resolveTxt.js" 运行此代码。
// dns.resolveTxt() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = dns.promises; // Passing IP to find the hostname TXT records dnsPromises.resolveTxt('tutorialspoint.com').then((response) => { console.log("TXT Records: ", response); })
输出
TXT Records: [ [ 'google-siteverification=S2zMIBQyc6WxHPiOdUzkWYvx_FKbf03xDOsI8OgG20A' ], [ 'v=spf1 ip4:116.202.79.150 include:_spf.google.com -all' ], [ 'google-site-verification=-RNr-P1jBNMarh7tMQEgXtlBVUi000DUphh8H7uSaQ' ] ]
示例 2
// dns.resolveTxt() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = dns.promises; // Setting ttl as true const options={ ttl:true, }; // Calling dnsPromises.resolveTxt() method // asynchronously (async function() { const records = await dnsPromises.resolveTxt( 'google.com', options); // Printing records console.log("TXT Records: ", records); })();
输出
TXT Records: [ [ 'MS=E4A68B9AB2BB9670BCE15412F62916164C0B20BB' ], [ 'apple-domain-verification=30afIBcvSuDV2PLX' ], ['globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8='], [ 'docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e' ], [ 'docusign=1b0a6754-49b1-4db5-8540-d2c12664b289' ], [ 'v=spf1 include:_spf.google.com ~all' ], [ 'google-site-verification=TV9-DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ' ], [ 'facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95' ], [ 'google-siteverification=wD8N7i1JTNTkezJ49swvWW48f8_9xveREV4oB-0Hf5o' ] ]
广告