Created
May 18, 2020 11:05
-
-
Save kappuccino/385b336c209b5a49efec41b671024778 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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