Skip to content

Instantly share code, notes, and snippets.

@tohagan
Created July 23, 2023 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tohagan/60846ba285c941df2bb07333af2fdc41 to your computer and use it in GitHub Desktop.
Save tohagan/60846ba285c941df2bb07333af2fdc41 to your computer and use it in GitHub Desktop.
Resolve a list of DNS names
// 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