Skip to content

Instantly share code, notes, and snippets.

@kappuccino
Created May 18, 2020 11:05
Show Gist options
  • Save kappuccino/385b336c209b5a49efec41b671024778 to your computer and use it in GitHub Desktop.
Save kappuccino/385b336c209b5a49efec41b671024778 to your computer and use it in GitHub Desktop.
const fs = require('fs')
const {promisify} = require('util')
var dns = require('dns')
function getMxRecords(domain){
return new Promise(resolve => {
dns.resolveMx(domain, function (err, addresses) {
if (err) return resolve(null)
let ex = addresses
.sort((a,b) => a.priority > b.priority)
.map(a => `${a.priority} ${a.exchange}`)
resolve(ex)
})
})
}
// Read domain from "./domaines.txt" with a domain every line
let out = []
;(async () => {
const raw = await promisify(fs.readFile)('./domaines.txt', 'utf8')
const domains = raw.split('\n').map(d => d.trim())
for await(const dom of domains){
let line = [dom]
const mx = await getMxRecords(dom)
if(mx && mx.length){
line.push(...mx)
}else{
line.push('NO-MX')
}
console.log(line.join('\t'))
out.push(line)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment