Node.js – dnsPromises.resolveSoa() 方法


dnsPromises.resolveSoa() 方法使用 DNS 協議來解析主機名的權威記錄(SOA 記錄)。如果解析成功,則使用以下屬性解析承諾

  • nsname

  • hostmaster

  • serial

  • refresh

  • retry

  • expire

  • minttl

語法

dnsPromises.resolveSoa( hostname )

引數

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

示例 1

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

// dns.resolveSoa() Demo Example

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

const dnsPromises = dns.promises;

// Passing IP to find the hostname TXT records
dnsPromises.resolveSoa('tutorialspoint.com').then((response) => { 
   console.log("SOA Records: ", response);
})

輸出

它將生成以下輸出 -

C:\home
ode>> node resolveSoa.js SOA Records: { nsname: 'pdns13.domaincontrol.com',    hostmaster: 'dns.jomax.net',    serial: 2021051700,    refresh: 28800,    retry: 7200,    expire: 604800,    minttl: 600 }

示例 2

我們來看另一個示例 -

// dns.resolveSoa() Demo Example

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

const dnsPromises = dns.promises;

// Setting ttl as true
const options={
   ttl:true,
};

// Calling dnsPromises.resolveSoa() method asynchronously
(async function() {
   const records = await dnsPromises.resolveSoa( 'google.com', options);

   // Printing records
   console.log("SOA Records: ", records);
})();

輸出

它將生成以下輸出 -

C:\home
ode>> node resolveSoa.js SOA Records: { nsname: 'ns1.google.com',    hostmaster: 'dns-admin.google.com',    serial: 379680302,    refresh: 900,    retry: 900,    expire: 1800,    minttl: 60 }

更新時間:24-11-2021

75 次瀏覽

開啟您的 職業生涯

透過完成課程取得認證

開始
廣告
© . All rights reserved.