Skip to content

Instantly share code, notes, and snippets.

@tomwassenberg
Last active October 31, 2019 19:00
Show Gist options
  • Save tomwassenberg/929bf896648f870a382ee2ced9629883 to your computer and use it in GitHub Desktop.
Save tomwassenberg/929bf896648f870a382ee2ced9629883 to your computer and use it in GitHub Desktop.
Queries an FQDN for a record type a certain amount of times, and lists the received statuses
#!/usr/bin/env bash
set -Eefuo pipefail
IFS=$'\n\t'
# Set these vars first
host="${1}"
record_type="${2}"
request_limit=5
declare -A status_count
run_dig() {
dig ${host} ${record_type} 2>&1 | grep -oP "(?<=status: )\w+"
}
print_totals() {
echo -en '\n---\n\n'
for status_type in "${!status_count[@]}"; do
echo "${status_type}:" "${status_count[$status_type]}/${request_limit}"
done
}
trap print_totals ERR EXIT
echo -en "Running ${request_limit} DNS queries...\n\n"
for (( count=0; count<request_limit; count++ )); do
result="$(run_dig)"
if [[ -z "${status_count[${result}]:-}" ]]; then
status_count[${result}]=0
fi
# shellcheck disable=SC2149
status_count[${result}]=$(( status_count[${result}] + 1))
sleep 1
done
echo "Finished all DNS queries."
@tomwassenberg
Copy link
Author

tomwassenberg commented Dec 2, 2017

Created to reproduce a bug in Cloudflare's nameservers, because they keep returning SERVFAIL's for queries for the SOA record of a CNAME'd hostname.

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