Created
July 23, 2023 04:52
-
-
Save tohagan/60846ba285c941df2bb07333af2fdc41 to your computer and use it in GitHub Desktop.
Resolve a list of DNS names
This file contains 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
// Accessing dns module | |
const dns = require('dns'); | |
async function run() { | |
const names = [ | |
'hostname1.com', | |
'hostname2.com', | |
] | |
for await (const name of names) { | |
// can use resolve4() to get IP4 or resolve6() to get IP6 addresses. | |
let ips = await dns.promises.resolve(name) | |
console.log('%s: %j', name, ips) | |
} | |
} | |
// Start | |
run() | |
.then(() => process.exit(0)) | |
.catch((err) => { console.error(err); process.exit(1) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment