Skip to content

Instantly share code, notes, and snippets.

@ldx
Last active May 17, 2021 18:55
Show Gist options
  • Save ldx/ab5d1a2cc6e0154a014bb486210cd051 to your computer and use it in GitHub Desktop.
Save ldx/ab5d1a2cc6e0154a014bb486210cd051 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const dns = require('dns');
const args = process.argv.slice(2)
const hostname = args[0]
fs.readFile('/etc/resolv.conf', (err, data) => {
if (err) {
console.dir(err);
} else {
console.log('resolv.conf:\n%s', data);
}
});
dns.resolveAny(hostname, (err, addresses) => {
if (err) {
console.error(err);
} else {
addresses.forEach((value) => {
console.log('resolve %s: %s', hostname, value);
})
}
})
dns.lookup(hostname, {family: 4}, (err, addr, family) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log('lookup %s: %s AF %d', hostname, addr, family);
process.exit(0);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment