Node.js – dns.resolveNaptr() 方法


dns.resolveNaptr() 方法使用 DNS 協議來解析主機名的基於正則表示式的單詞(NAPTR 記錄)。傳遞給回撥函式的地址引數將包含一個物件陣列,這些物件具有以下屬性:-

  • 標誌

  • 服務

  • 正則表示式

  • 置換

  • 順序

  • 優先順序

語法

dns.resolveNaptr(hostname, callback)

引數

  • hostname – 此引數獲取要解析的主機名的輸入。

  • callback – 此函式將捕獲錯誤(如果有)。

    • 記錄 – 返回主機名的 NAPTR 記錄。

示例 1

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

// dns.resolveNaptr() Demo Example

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

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

輸出

QueryReqWrap {
   bindingName: 'queryNaptr',
   callback: [Function],
   hostname: 'tutorialspoint.com',
   oncomplete: [Function: onresolve],
   ttl: false,
   channel: ChannelWrap {} }
NAPTR Records: undefined

示例 2

// dns.resolveNaptr() Demo Example

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

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

輸出

NAPTR Records: undefined

更新於:2021-10-29

59 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.