Skip to content

Instantly share code, notes, and snippets.

@nobiit
Created August 9, 2022 07:28
Show Gist options
  • Save nobiit/df023f0f0171ece79f8ceb58cd48e277 to your computer and use it in GitHub Desktop.
Save nobiit/df023f0f0171ece79f8ceb58cd48e277 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
DNS_SERVER=${1}
DOMAIN=${2:-google.com}
COUNT=${3:-100}
printf "Testing DNS for %s on %s ...\n" ${DOMAIN} ${DNS_SERVER}
for _ in $(seq 1 ${COUNT}); do
start_time=$(date +'%s')
result=$(dig ${DOMAIN} @${DNS_SERVER} || true)
end_time=$(date +'%s')
time=$(expr ${end_time} - ${start_time} || true)
echo $(echo "${result}" | grep -oP ';; Query time: \K([0-9]+) msec') "${time}s"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment