Last active
November 23, 2021 21:08
-
-
Save davidderus/5a6e73d6a20e627ae95804e19c93130c to your computer and use it in GitHub Desktop.
DNS Response Time Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh - | |
#=============================================================================== | |
# | |
# FILE: dns-tests.zsh | |
# | |
# USAGE: ./dns-tests.sh google.fr | |
# | |
# DESCRIPTION: DNS Response Time Checker | |
# | |
# REQUIREMENTS: dig | |
# AUTHOR: David Dérus | |
# ORGANIZATION: | |
# CREATED: 13.05.2017 11:58 | |
# REVISION: 1.1 | |
# | |
#=============================================================================== | |
set -o nounset # Treat unset variables as an error | |
# DNS_SERVERS: | |
# - 8.8.8.8 = Google DNS | |
# - 208.67.222.222 = OpenDNS | |
DNS_SERVERS=(8.8.8.8 208.67.222.222) | |
TEST_DOMAINS=("$@") | |
if [ $# -eq 0 ]; then | |
echo "You must provide at least one valid domain name to resolve against" | |
exit 1 | |
fi | |
echo "Starting test at `date +%Y-%m-%d:%H:%M:%S`" | |
echo "Using test domains: ${TEST_DOMAINS[*]}" | |
echo | |
for domain in ${TEST_DOMAINS[@]}; do | |
echo "= Querying for $domain:\n" | |
for dns in ${DNS_SERVERS[@]}; do | |
echo -ne "> Using DNS $dns: " | |
dig_output=`dig "@$dns" $domain` | |
query_time=`echo $dig_output | egrep -o "Query time: \d+ \w+" | cut -c 13-` | |
response_addresses=(`echo $dig_output | egrep -o "$domain.\s+\d+\s+IN\s+A\s+.+" | egrep -o "\d+.\d+.\d+.\d+$"`) | |
if [[ -z "$response_addresses" ]]; then | |
echo "No results" | |
else | |
echo "Found ${response_addresses[*]} in $query_time" | |
fi | |
done | |
echo | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment