dns.resolveSoa()方法是dns模塊的內置應用程序編程接口,用於使用DNS協議解析SOA或指定主機名的授權記錄的開始。
用法:
dns.resolveSoa( hostname, callback )
參數:此方法具有上述和以下所述的兩個參數:
- hostname:此參數指定一個字符串,該字符串表示要解析的主機名。
- callback:它指定在主機名進行DNS解析之後要調用的函數。
- error:如果生成,則指定錯誤。
- addresses:它是一個字符串數組,表示返回的主機名的授權開始(SOA)記錄。
返回值:該方法通過回調函數返回錯誤地址。這些數據作為參數傳遞給回調函數。地址參數將包含nsname,hostmaster,serial,refresh,retry,expire和minttl屬性。
以下示例說明了Node.js中dns.resolveSoa()方法的使用:
範例1:
// Node.js program to demonstrate the
// dns.resolveSoa() method
// Accessing dns module
const dns = require('dns');
// Calling dns.resolveSoa() method for hostname
// geeksforgeeks.org and displaying them in
// console as a callback
dns.resolveSoa('geeksforgeeks.org', (err,
addresses) => console.log('SOA records:%j', addresses));輸出:
SOA records:{
"nsname":"ns-869.awsdns-44.net",
"hostmaster":"awsdns-hostmaster.amazon.com",
"serial":1,
"refresh":7200,
"retry":900,
"expire":1209600,
"minttl":86400
}
範例2:
// Node.js program to demonstrate the
// dns.resolveSoa() method
// Accessing dns module
const dns = require('dns');
// Calling dns.resolveSoa() method for hostname
// google.com printing them in console as a callback
dns.resolveSoa('google.com', (err,
addresses) => console.log('SOA records:%j', addresses));輸出:
SOA records:{
"nsname":"ns1.google.com",
"hostmaster":"dns-admin.google.com",
"serial":287530106,
"refresh":900,
"retry":900,
"expire":1800,
"minttl":60
}
注意:上麵的程序將通過使用node index.js命令。
參考: https://nodejs.org/api/dns.html#dns_dns_resolvesoa_hostname_callback
相關用法
注:本文由純淨天空篩選整理自gekcho大神的英文原創作品 Node.js | dns.resolveSoa() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
