G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 3rd, 2020 213 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. command -v bc > /dev/null || { echo "bc was not found. Please install bc."; exit 1; }
  4. { command -v drill > /dev/null && dig=drill; } || { command -v dig > /dev/null && dig=dig; } || { echo "dig was not found. Please install dnsutils."; exit 1; }
  5.  
  6.  
  7. # Local DNS resolvers
  8. NAMESERVERS=`cat /etc/resolv.conf | grep ^nameserver | cut -d " " -f 2 | sed 's/\(.*\)/&#&/'`
  9.  
  10. # Upstream DNS resolvers
  11. # Non-standard ports may be specified e.g. 127.0.0.1:5353#mydns
  12. PROVIDERS="
  13. 149.112.121.20#canadianshield
  14. 9.9.9.9#quad9
  15. 1.1.1.2#cloudflare2
  16. "
  17.  
  18. # Number of domains to test
  19. NUM_DOMAINS2TEST=20
  20.  
  21. # Random domains to choose from
  22. RANDOM_DOMAINS=(
  23. `curl -sS https://raw.githubusercontent.com/opendns/public-domain-lists/master/opendns-top-domains.txt`
  24. `curl -sS https://raw.githubusercontent.com/opendns/public-domain-lists/master/opendns-random-domains.txt`
  25. )
  26.  
  27. heading="DOMAINS TO TEST: "; echo -n "$heading"
  28. results_indent=$((${#heading} - 3))
  29. results_tempfile=`mktemp`
  30. domains2test=""
  31. num_random_domains=${#RANDOM_DOMAINS[*]}
  32.  
  33. for ((i=1; i <= $NUM_DOMAINS2TEST; i++)); do
  34.     if [ $i -gt 1 ]; then
  35.         printf "%-${#heading}s" ""
  36.     fi
  37.  
  38.     domain_id=`printf "%5s" "($i) "`; echo -n "$domain_id"
  39.     domain_heading="   $domain_id"
  40.     results_header="$results_header$domain_heading"
  41.     random_domain=${RANDOM_DOMAINS[$RANDOM % num_random_domains]}; echo $random_domain
  42.     domains2test="$domains2test $random_domain"
  43. done
  44.  
  45. avg_heading="  AVERAGE"
  46. results_header="$results_header$avg_heading"
  47. printf "\n%-${results_indent}s" ""
  48. echo "$results_header"
  49.  
  50. for p in $NAMESERVERS $PROVIDERS; do
  51.     pip=${p%%#*}
  52.     pname=${p##*#}
  53.     ftime=0
  54.  
  55.     printf "%-${results_indent}s" "$pname" | tee -a $results_tempfile
  56.     for d in $domains2test; do
  57.         ttime=`$dig +tries=1 +time=2 +stats @${pip/:/" -p"} $d | grep "Query time:" | cut -d : -f 2- | cut -d " " -f 2`
  58.         if [ -z "$ttime" ]; then
  59.             #let's have time out be 1s = 1000ms
  60.             ttime=1000
  61.         elif [ "x$ttime" = "x0" ]; then
  62.             ttime=1
  63.         fi
  64.  
  65.         printf "%${#domain_heading}s" "$ttime ms" | tee -a $results_tempfile
  66.         ftime=$((ftime + ttime))
  67.     done
  68.     avg=`bc -lq <<< "scale=2; $ftime/$NUM_DOMAINS2TEST"`
  69.  
  70.     printf "%${#avg_heading}s\n" $avg | tee -a $results_tempfile
  71. done
  72.  
  73. printf "\n%-${results_indent}s" "SORTED BY AVG."
  74. echo "$results_header"
  75. sort -g -k$((2*$NUM_DOMAINS2TEST + 2)) $results_tempfile
  76. rm $results_tempfile
  77.  
  78.  
  79. exit 0;
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top