Last active
January 29, 2025 11:35
-
-
Save CanadianBaconBoi/640e8ed7fe08d99a5361dd587ef4af10 to your computer and use it in GitHub Desktop.
Dns Benchmark Script
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/bash | |
dnsServers=( | |
"Google|8.8.8.8|8.8.4.4" | |
"ControlD|76.76.2.0|76.76.10.0" | |
"Quad9|9.9.9.9|149.112.112.112" | |
"Cloudflare|1.1.1.1|1.0.0.1" | |
) | |
domains=( | |
"google.com" | |
"discord.com" | |
"microsoft.com" | |
"yandex.ru" | |
"x.com" | |
"gentoo.org" | |
"github.com" | |
"stackoverflow.com" | |
"wpengine.com" | |
"opensource.com" | |
) | |
paramNumIters="${1:-10}" | |
echo " | |
--- Simple DNS Benchmark by CanadianBacon --- | |
# Iterations: $paramNumIters | |
# DNS Providers: ${#dnsServers[@]} | |
# Domains: ${#domains[@]} | |
# Time per DNS provider: ~$(($paramNumIters*${#domains[@]}/10*2)) seconds | |
First passed parameter is number of iterations. | |
A higher number will provide more accurate results at the expense of runtime. | |
e.g. \`${0:-./dnsbenchmark.sh} 100\` will run 100 iterations per dns server \(200 per config entry due to alternate DNS\) | |
The DNS servers and domains are configurable in the script. | |
--------------------------------------------- | |
" | |
for server in ${dnsServers[@]}; | |
do | |
server=(${server//|/ }) | |
latency=0 | |
iters=0 | |
for domain in ${domains[@]}; | |
do | |
for i in $(eval echo "{1..${paramNumIters}}"); | |
do | |
result=$(dig @${server[1]} ${domain} +noall +stats | head -n1 | grep -Po '[0-9]+') | |
latency=$((latency + result)) | |
iters=$((iters + 1)) | |
sleep 0.1 | |
done | |
done | |
latency=$((latency / iters)) | |
secondaryLatency=0 | |
iters=0 | |
for domain in ${domains[@]}; | |
do | |
for i in $(eval echo "{1..${paramNumIters}}"); | |
do | |
result=$(dig @${server[2]} ${domain} +noall +stats | head -n1 | grep -Po '[0-9]+') | |
secondaryLatency=$((secondaryLatency + result)) | |
iters=$((iters + 1)) | |
sleep 0.1 | |
done | |
done | |
secondaryLatency=$((secondaryLatency / iters)) | |
echo "${server[0]} [${server[1]} / ${server[2]}] : ${latency} ms / ${secondaryLatency} ms" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removed OpenDNSHome as there seems to be some censorship