Skip to content

Instantly share code, notes, and snippets.

@crypt0rr
Created October 9, 2024 14:09
Show Gist options
  • Save crypt0rr/fcfb04f143ad823382e12f56f6b2e3d1 to your computer and use it in GitHub Desktop.
Save crypt0rr/fcfb04f143ad823382e12f56f6b2e3d1 to your computer and use it in GitHub Desktop.
DNS Performance Tester - Based on DNSperf
#!/bin/bash
# Ubuntu / Debian dnsperf is required to run this script, follow the installation steps below
## sudo apt-get update && sudo apt-get install -y build-essential libbind-dev libkrb5-dev libssl-dev libcap-dev libxml2-dev wget curl
## wget https://www.dns-oarc.net/files/dnsperf/dnsperf-2.3.3.tar.gz
## tar -xvzf dnsperf-2.3.3.tar.gz
## cd dnsperf-2.3.3
## ./configure
## make
## sudo make install
## dnsperf -h
# macOS
## brew install dnsperf
# List of DNS servers to test
dns_servers=(
"8.8.8.8" # Google DNS
"8.8.4.4" # Google DNS
"1.1.1.1" # Cloudflare DNS
"1.0.0.1" # Cloudflare DNS
"208.67.222.222" # OpenDNS
"208.67.220.220" # OpenDNS
"9.9.9.9" # Quad9 DNS
"149.112.112.112" # Quad9 DNS
"8.26.56.26" # Comodo Secure DNS
"8.20.247.20" # Comodo Secure DNS
"185.228.168.168" # CleanBrowsing (Family Filter)
"185.228.169.168" # CleanBrowsing (Family Filter)
"156.154.70.3" # Neustar UltraDNS (Family Protection)
"156.154.71.3" # Neustar UltraDNS (Family Protection)
"77.88.8.8" # Yandex DNS
"77.88.8.1" # Yandex DNS
"94.140.14.14" # AdGuard DNS
"94.140.15.15" # AdGuard DNS
"64.6.64.6" # Verisign DNS
"64.6.65.6" # Verisign DNS
"208.76.50.50" # SmartViper DNS
"208.76.51.51" # SmartViper DNS
"84.200.69.80" # DNS.WATCH
"84.200.70.40" # DNS.WATCH
"4.2.2.1" # Level3 DNS
"4.2.2.2" # Level3 DNS
"216.146.35.35" # Dyn DNS
"216.146.36.36" # Dyn DNS
)
# Path to your DNS query file
query_file="queries.txt"
# Output file for logging results
output_file="dns_performance_log.txt"
# Initialize variables for tracking the best-performing DNS servers
best_qps=0
best_qps_server=""
best_latency=1000 # Start with a very high latency
best_latency_server=""
lowest_error_rate=1000 # Start with a very high error rate
best_error_rate_server=""
# Initialize the log file
echo "DNS Performance Test Results" > $output_file
echo "==============================" >> $output_file
# Loop through each DNS server and test
for server in "${dns_servers[@]}"
do
echo "Testing DNS server: $server"
# Capture the performance output for each DNS server
result=$(dnsperf -s $server -d $query_file 2>&1)
# Extract relevant performance metrics from the output using grep/awk
qps=$(echo "$result" | grep "Queries per second" | awk '{print $4}')
avg_latency=$(echo "$result" | grep "Average Latency" | awk '{print $4}')
errors=$(echo "$result" | grep "Queries lost" | awk '{print $4}')
# Remove percentage sign from errors and convert it to a numeric value
errors=$(echo "$errors" | sed 's/%//')
# Check if values were extracted successfully, fallback to N/A if not
qps=${qps:-"N/A"}
avg_latency=${avg_latency:-"N/A"}
errors=${errors:-"N/A"}
# Log the results into the output file
echo "DNS Server: $server" >> $output_file
echo "Queries per second: $qps" >> $output_file
echo "Average Latency (s): $avg_latency" >> $output_file
echo "Error Rate: $errors" >> $output_file
echo "------------------------------" >> $output_file
# Check if QPS is the highest
if [[ "$qps" != "N/A" && $(echo "$qps > $best_qps" | bc) -eq 1 ]]; then
best_qps=$qps
best_qps_server=$server
fi
# Check if latency is the lowest
if [[ "$avg_latency" != "N/A" && $(echo "$avg_latency < $best_latency" | bc) -eq 1 ]]; then
best_latency=$avg_latency
best_latency_server=$server
fi
# Check if error rate is the lowest
if [[ "$errors" != "N/A" && $(echo "$errors < $lowest_error_rate" | bc) -eq 1 ]]; then
lowest_error_rate=$errors
best_error_rate_server=$server
fi
done
# Display the log file contents
cat $output_file
# Display the summary of the best-performing DNS servers
echo ""
echo "Best Performing DNS Servers Summary"
echo "==================================="
echo "Highest Queries per Second: $best_qps (DNS Server: $best_qps_server)"
echo "Lowest Average Latency: $best_latency s (DNS Server: $best_latency_server)"
echo "Lowest Error Rate: $lowest_error_rate (DNS Server: $best_error_rate_server)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment