Node.js - dns.resolveTxt() 方法


dns.resolveTxt()方法使用 DNS 協議解析主機名的文字查詢(TXT 記錄)。傳遞給回撥函式的addresses引數是一個二維陣列,其中包含可用於主機名的文字記錄陣列。

語法

dns.resolveTxt(hostname, callback)

引數

  • hostname - 此引數接受要解析的主機名的輸入

  • callback - 該函式將捕獲錯誤(如果有)。

    • records - 返回主機名的 TXT 記錄。

示例1

建立一個名為"resolveTxt.js"的檔案並複製以下程式碼段。建立檔案後,使用命令"node resolveTxt.js"執行此程式碼。

// dns.resolveTxt() Demo Example

// Importing the dns module
const dns = require('dns');

// Passing the argument below
dns.resolveTxt('tutorialspoint.com', (err, records) => console.log('TXT Records: %j', records));

輸出

C:\home
ode>> node resolveTxt.js TXT Records: [["google-site-verification=-RNrP1jBNMarh7tMQEgXtlBVUi000DUph-h8H7uSaQ"],["google-siteverification=S2zMIBQyc6WxHPiOdUzkWYvx_FKbf03xDOsI8OgG20A"],["v=sp f1 ip4:116.202.79.150 include:_spf.google.com -all"]]

示例 2

// dns.resolveTxt() Demo Example

// Importing the dns module
const dns = require('dns');

// Passing the argument below
dns.resolveTxt('google.com', (err, records) => console.log('TXT Records: %j', records));

輸出

C:\home
ode>> node resolveNaptr.js TXT Records: [["facebook-domainverification=22rm551cu4k0ab0bxsw536tlds4h95"],["docusign=1b0a6754 -49b1-4db5-8540-d2c12664b289"],["apple-domainverification=30afIBcvSuDV2PLX"],["docusign=05958488-4752-4ef2- 95eb-aa7ba8a3bd0e"],["globalsign-smimedv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8="],["google-siteverification=TV9- DBe4R80X4v0M4U_bd_J9cpOJM0nikft0jAgjmsQ"],["v=spf1 include:_spf.google.com ~all"],["google-siteverification=wD8N7i1JTNTkezJ49swvWW48f8_9xveREV4oB0Hf5o"],["MS=E4A68B9AB2BB9670BCE15412F62916164C0B20BB"]]

更新於:2021 年 10 月 29 日

321 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.