Skip to content

Instantly share code, notes, and snippets.

@andris9
Created November 11, 2019 20:28
Show Gist options
  • Save andris9/2f04a5b23c8253f814c2c49e4324448f to your computer and use it in GitHub Desktop.
Save andris9/2f04a5b23c8253f814c2c49e4324448f to your computer and use it in GitHub Desktop.
const dns = require('dns').promises;
// how many parallel "workers" to use
let batchSize = 3;
// domain list to process
let domains = [
'neti.ee',
'hot.ee',
'zone.ee',
'telia.ee',
'a.ee',
'delfi.ee',
'postimees.ee',
'nali.ee'
];
async function main() {
let results = [];
while (domains.length) {
let promises = [];
for (let i = 0; i < batchSize && domains.length; i++) {
let domain = domains.shift();
if (domain) {
promises.push(
(async () => {
try {
return await dns.resolveAny(domain);
} catch (err) {
return false;
}
})()
);
}
}
if (promises.length) {
results = results.concat(await Promise.all(promises));
}
}
console.log(results);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment