Node.js - dns.resolveMx() 方法
dns.resolveMx() 方法使用 DNS 協議來解析主機名的郵件交換 (MX) 記錄。傳遞給 callback 函式的 addresses 引數將包含一個物件陣列,其中包含優先順序和交換物件。
語法
dns.resolveMx(hostname, callback)
引數
hostname – 此引數用於輸入要解析的主機名。
callback – 此函式將捕獲錯誤(如果存在)。
records – 返回主機名的 Mx 記錄。
示例 1
建立一個名為 "resolveMx.js" 的檔案,並複製以下程式碼片段。建立檔案後,使用命令 "node resolveMx.js" 執行此程式碼,如下例所示 −
// dns.resolveMx() Demo Example // Importing the dns module const dns = require('dns'); // Passing the argument below dns.resolveMx('tutorialspoint.com', (err, records) => console.log('addresses: %j', records));
輸出
C:\home
ode>> node resolveMx.js addresses: [{"exchange":"aspmx.l.google.com","priority":1}, {"exchange":"alt4.aspmx.l.google.com","priority":10},{"exchange":"alt3.aspmx.l.google.com","priority":10}, {"exchange":"alt2.aspmx.l.google.com","priority":5},{"exchange":"alt1.aspmx.l.google.com","priority":5}]
示例 2
// dns.resolveMx() Demo Example // Importing the dns module const dns = require('dns'); // Passing the argument below dns.resolveMx('google.com', (err, records) => console.log('addresses: %j', records));
輸出
C:\home
ode>> node resolveMx.js addresses: [{"exchange":"alt1.aspmx.l.google.com","priority":20},{"exchange":"alt4.aspmx.l.google.com","priority":50},{"exchange":"alt2.aspmx.l.google.com","priority":30},{"exchange":"alt3.aspmx.l.google.com","priority":40},{"exchange":"aspmx.l.google.com","priority":10}]
廣告