@@ -26,6 +26,7 @@ IPV6_ONLY=0
2626SKIP_PING=0
2727NO_COLOR=0
2828TEST_COUNT=5
29+ TEST_DOMAIN=" google.com"
2930
3031# Help function
3132show_help () {
@@ -35,6 +36,7 @@ show_help() {
3536 printf ' -4, --ipv4-only Test only IPv4 DNS servers\n'
3637 printf ' -6, --ipv6-only Test only IPv6 DNS servers (requires IPv6 connectivity)\n'
3738 printf ' -n, --count N Number of tests per server (default: 5)\n'
39+ printf ' -d, --domain NAME Domain/IP to use for DNS queries (default: google.com)\n'
3840 printf ' -q, --quick Quick mode (3 tests per server)\n'
3941 printf ' --no-ping Skip ping correlation test\n'
4042 printf ' --no-color Disable colored output\n'
@@ -44,6 +46,7 @@ show_help() {
4446 printf ' %s # Run full test (IPv4 + IPv6 if available)\n' " $( basename " $0 " ) "
4547 printf ' %s -4 # Test only IPv4 servers\n' " $( basename " $0 " ) "
4648 printf ' %s -q # Quick test with fewer iterations\n' " $( basename " $0 " ) "
49+ printf ' %s -d github.com # Use github.com for DNS queries\n' " $( basename " $0 " ) "
4750 printf ' %s --no-ping # Skip ping correlation analysis\n\n' " $( basename " $0 " ) "
4851 exit 0
4952}
@@ -78,6 +81,22 @@ while [ $# -gt 0 ]; do
7881 TEST_COUNT=3
7982 shift
8083 ;;
84+ -d|--domain)
85+ if [ -n " $2 " ]; then
86+ # Validate: must be a single domain/IP (no spaces)
87+ case " $2 " in
88+ * " " * |* " " * )
89+ printf ' Error: --domain requires a single domain or IP (no spaces)\n'
90+ exit 1
91+ ;;
92+ esac
93+ TEST_DOMAIN=$2
94+ shift 2
95+ else
96+ printf ' Error: --domain requires a domain name or IP address\n'
97+ exit 1
98+ fi
99+ ;;
81100 --no-ping)
82101 SKIP_PING=1
83102 shift
@@ -123,15 +142,6 @@ else
123142 NC=$( printf ' \033[0m' ) # No Color
124143fi
125144
126- # Test domains (popular sites for comprehensive testing)
127- TEST_DOMAINS=" google.com youtube.com facebook.com instagram.com chatgpt.com x.com whatsapp.com reddit.com wikipedia.org amazon.com tiktok.com pinterest.com cloudflare.com github.com netflix.com"
128-
129- # Convert to list for counting
130- # shellcheck disable=SC2086
131- # Note: $TEST_DOMAINS intentionally unquoted to split into array
132- set -- $TEST_DOMAINS
133- TEST_DOMAIN_COUNT=$#
134-
135145# Check for IPv6 connectivity
136146check_ipv6_connectivity () {
137147 printf ' %bChecking IPv6 connectivity...%b\n' " ${CYAN} " " ${NC} "
@@ -355,20 +365,6 @@ count_dns_servers() {
355365 echo " $DNS_SERVERS " | grep -c -v " ^$"
356366}
357367
358- # Function to get nth test domain
359- get_test_domain () {
360- local index=$1
361- local count=0
362- for domain in $TEST_DOMAINS ; do
363- count=$(( count + 1 ))
364- if [ $count -eq " $index " ]; then
365- echo " $domain "
366- return
367- fi
368- done
369- echo " google.com" # fallback
370- }
371-
372368# Function to test DNS response time
373369test_dns () {
374370 local dns_server=$1
@@ -485,7 +481,7 @@ echo ""
485481printf ' Total DNS Servers: %s (IPv4: %s, IPv6: %s)\n' " ${DNS_COUNT} " " ${DNS_IPV4_COUNT} " " ${DNS_IPV6_COUNT} "
486482printf ' Tests per server: %s\n' " ${TEST_COUNT} "
487483printf ' Total tests to run: %s\n' " ${total_tests} "
488- printf ' Test domains : %s popular websites \n' " ${TEST_DOMAIN_COUNT } "
484+ printf ' Test domain : %s\n' " ${TEST_DOMAIN } "
489485echo " "
490486printf ' %bThis will take a few minutes to complete...%s\n' " ${YELLOW} " " ${NC} "
491487echo " "
@@ -525,17 +521,16 @@ echo "$DNS_SERVERS" | grep -v "^$" | while IFS='|' read -r dns_name dns_ip; do
525521 printf " [%3d/%3d] Testing %-35s (%s) ... \n" " $current " " $total " " $dns_name " " $dns_ip "
526522
527523 # Store results for this DNS server
524+ # Run a warmup query to prime the cache (prevents first-query bias)
525+ test_dns " $dns_ip " " $TEST_DOMAIN " > /dev/null
526+
528527 times=" "
529528 failed=0
530529
531- # Test multiple times with different domains
530+ # Test multiple times with the same domain (measures cached response time)
532531 i=1
533532 while [ $i -le $TEST_COUNT ]; do
534- # Rotate through test domains
535- domain_index=$(( (i - 1 ) % TEST_DOMAIN_COUNT + 1 ))
536- domain=$( get_test_domain $domain_index )
537-
538- response_time=$( test_dns " $dns_ip " " $domain " )
533+ response_time=$( test_dns " $dns_ip " " $TEST_DOMAIN " )
539534
540535 if [ " $response_time " = " 0" ] || [ -z " $response_time " ]; then
541536 failed=$(( failed + 1 ))
0 commit comments