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' ] ]
廣告