Skip to content

Instantly share code, notes, and snippets.

@fetwar
Last active October 31, 2023 06:37
Show Gist options
  • Save fetwar/e7a48433fc32539af9c43a40bb285880 to your computer and use it in GitHub Desktop.
Save fetwar/e7a48433fc32539af9c43a40bb285880 to your computer and use it in GitHub Desktop.
Use dig to fetch multiple DNS records of a domain.
#!/usr/bin/env bash
defaultRecordTypes=( A CNAME MX TXT SOA PTR SRV )
# Domain name input
if [ -z $1 ]; then
echo "Error: domain argument expected"
exit 1
fi
domain=$1
shift
# use arguments supplied, default to $defaultRecordTypes if none supplied
dnsRecordTypes=( $@ )
dnsRecordTypes=( "${dnsRecordTypes[@]:-${defaultRecordTypes[@]}}" )
echo Records: ${dnsRecordTypes[@]}
for argument in "${dnsRecordTypes[@]}"; do
echo
echo $argument
# Print result indented 4 spaces
dig +nocmd +noall +answer +authority $domain $argument | sed 's/^/ /'
done
@fetwar
Copy link
Author

fetwar commented Mar 28, 2023

This does the most you can do with dig AFAIK, however it still fails to return a comprehensive list of the records.

I've noted it doesn't return these, probably a bunch of others too.

  • DMARC
  • DKIM

It does still mimic the functionality of nslookup.io though

I wouldn't trust it as far as I can throw it, but it was fun to make

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment