Created
July 27, 2024 12:45
-
-
Save oazabir/071b4921848418bbe09c851169450bae to your computer and use it in GitHub Desktop.
Test DNS resolution time
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 | |
# List of top 100 domains | |
domains=( | |
"google.com" | |
"youtube.com" | |
"facebook.com" | |
"baidu.com" | |
"wikipedia.org" | |
"yahoo.com" | |
"reddit.com" | |
"google.co.in" | |
"qq.com" | |
"taobao.com" | |
"amazon.com" | |
"tmall.com" | |
"twitter.com" | |
"sohu.com" | |
"instagram.com" | |
"vk.com" | |
"jd.com" | |
"sina.com.cn" | |
"weibo.com" | |
"live.com" | |
"360.cn" | |
"yandex.ru" | |
"blogspot.com" | |
"netflix.com" | |
"linkedin.com" | |
"twitch.tv" | |
"pages.tmall.com" | |
"mail.ru" | |
"microsoft.com" | |
"aliexpress.com" | |
"pinterest.com" | |
"google.co.jp" | |
"xvideos.com" | |
"google.de" | |
"office.com" | |
"google.co.uk" | |
"bing.com" | |
"google.fr" | |
"google.com.br" | |
"google.ru" | |
"google.it" | |
"google.es" | |
"google.ca" | |
"google.com.hk" | |
"ebay.com" | |
"msn.com" | |
"pornhub.com" | |
"google.com.mx" | |
"whatsapp.com" | |
"yahoo.co.jp" | |
"google.co.kr" | |
"google.com.tr" | |
"google.com.au" | |
"xhamster.com" | |
"imgur.com" | |
"google.com.ar" | |
"google.pl" | |
"google.co.th" | |
"google.nl" | |
"google.com.sa" | |
"google.co.id" | |
"google.com.eg" | |
"google.ae" | |
"google.com.sg" | |
"google.com.ua" | |
"google.co.za" | |
"naver.com" | |
"babytree.com" | |
"alipay.com" | |
"microsoftonline.com" | |
"hao123.com" | |
"wikia.com" | |
"myshopify.com" | |
"quora.com" | |
"tumblr.com" | |
"google.gr" | |
"google.com.ph" | |
"google.ro" | |
"google.cl" | |
"google.se" | |
"google.pt" | |
"google.com.ng" | |
"google.ch" | |
"google.be" | |
"google.com.my" | |
"google.cz" | |
"google.co.ve" | |
"google.hu" | |
"ok.ru" | |
"m.baidu.com" | |
"soso.com" | |
"google.at" | |
"google.dz" | |
"google.com.pk" | |
"google.ie" | |
"google.co.nz" | |
"google.com.vn" | |
"google.sk" | |
"google.co" | |
"google.no" | |
) | |
# Output file to record results | |
OUTPUT_FILE="dns_query_results.log" | |
# Temporary file to store response times | |
TEMP_FILE=$(mktemp) | |
# Initialize output file | |
echo "DNS Query Results" > $OUTPUT_FILE | |
echo "Timestamp, Domain, Response Time (ms)" >> $OUTPUT_FILE | |
# Function to perform a DNS query | |
perform_query() { | |
local domain=$1 | |
local start_time=$(date +%s%3N) | |
local response_time=$(dig +tcp +stats $domain | grep "Query time:" | awk '{print $4}') | |
local end_time=$(date +%s%3N) | |
# If response_time is empty, it means dig failed, set a large response time | |
if [[ -z "$response_time" ]]; then | |
response_time=9999 | |
fi | |
local timestamp=$(date +'%Y-%m-%d %H:%M:%S') | |
echo "$timestamp, $domain, $response_time" >> $OUTPUT_FILE | |
if (( response_time > 300 )); then | |
echo "$timestamp, $domain, $response_time" >> dns_queries_over_300ms.log | |
fi | |
echo "$response_time" >> $TEMP_FILE | |
} | |
# Start the time limit | |
end_time=$((SECONDS + 300)) | |
# Perform queries for 5 minutes | |
while [[ $SECONDS -lt $end_time ]]; do | |
# Get a random domain from the array | |
domain=${domains[RANDOM % ${#domains[@]}]} | |
perform_query $domain | |
sleep 1 | |
done | |
# Calculate mean response time | |
total_response_time=$(awk '{ sum += $1 } END { print sum }' $TEMP_FILE) | |
num_queries=$(wc -l < $TEMP_FILE) | |
mean_response_time=$(echo "scale=2; $total_response_time / $num_queries" | bc) | |
# Output mean response time | |
echo "Mean Response Time: $mean_response_time ms" >> $OUTPUT_FILE | |
# Clean up temporary file | |
rm $TEMP_FILE | |
echo "DNS querying complete. Results are in $OUTPUT_FILE and dns_queries_over_300ms.log." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment