Node.js – dns.resolvePtr() 方法


dns.resolvePtr() 方法透過 DNS 協議解決主機名的指標記錄(PTR 記錄)。傳遞給回撥函式的 addresses 引數將包含答覆記錄(作為字串陣列)。

語法

dns.resolvePtr(hostname, callback)

引數

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

  • callback - 此函式將在出現時捕獲錯誤。

    • records − 返回主機名的 PTR 記錄。

示例 1

建立一個名為 “resolvePtr.js” 的檔案,並複製以下程式碼。建立檔案後,使用以下示例所示的命令 “node resolvePtr.js” 執行此程式碼

// dns.resolvePtr() Demo Example

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

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

輸出

PTR Records: undefined

示例 2

我們再舉一個例子 -

// dns.resolvePtr() Demo Example

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

// Passing the argument below
dns.resolvePtr('stackoverflow.com', (err, records) => console.log('PTR Records: %j', records));

輸出

PTR Records: undefined

更新於: 24-11-2021

82 次瀏覽

開啟職業生涯

完成課程即可獲得認證

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