Created
November 11, 2019 20:28
-
-
Save andris9/2f04a5b23c8253f814c2c49e4324448f 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 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