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}]
广告