catkin

BSNL_DNS_server_performance_test.sh

Oct 19th, 2011
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/bash
  2.  
  3. set -o posix
  4. set -o nounset
  5. shopt -s extglob # allow extended pattern matching operators
  6.  
  7. # Executables
  8. # ~~~~~~~~~~~
  9. # So can change to suit OS variant
  10. nslookup='/usr/bin/nslookup'
  11. sort='/usr/bin/sort'
  12.  
  13. #--------------------------
  14. # Name: test_servers
  15. # Purpose: tests response times of list of servers
  16. # $1 - list of servers
  17. # $2 - results heading
  18. #--------------------------
  19. function test_servers {
  20.  
  21.     local oIFS out secs server
  22.  
  23.     out=''
  24.     for server in $1
  25.     do
  26.         echo -n '.'
  27.         # DEVELOPMENT NOTE: -timeout=5 in command below does not seem to be effective; default 15 timeout operates
  28.         secs="$(/usr/bin/time -f '%e' $nslookup '-timeout=5' 'www.google.com' $server 2>&1 1>/dev/null)"
  29.         out="$out
  30.     $secs $server"
  31.     done
  32.    
  33.     out="$(echo "$out" | $sort --general-numeric-sort)"
  34.    
  35.     echo
  36.     echo "$2"
  37.     oIFS="$IFS"
  38.     IFS='
  39.     '
  40.     for buf in $out
  41.     do
  42.         IFS="$oIFS"
  43.         IP_address="${buf#* }"
  44.         response_time="${buf% *}"
  45.         if [[ ${response_time%.*} -lt 5 ]]; then
  46.             response_time="$response_time seconds"
  47.         else
  48.             response_time='Timed out'
  49.         fi
  50.         printf '%16s  %s\n' "$IP_address" "$response_time"
  51.     done
  52.  
  53.  
  54.     return 0
  55.  
  56. }  # end of function test_servers
  57.  
  58. BSNL_servers='
  59. 61.1.96.69
  60. 61.1.96.71
  61. 61.1.96.72
  62. 218.248.240.23
  63. 218.248.240.135
  64. 218.248.240.180
  65. 218.248.240.181
  66. 218.248.240.208
  67. 218.248.255.139
  68. 218.248.255.145
  69. 218.248.255.146
  70. '
  71.  
  72. #echo 'DEBUG: setting small BSNL DNS server list'
  73. #BSNL_servers='
  74. #218.248.240.23
  75. #218.248.240.208
  76. #'
  77.  
  78. OpenDNS_servers='
  79. 208.67.222.222
  80. 208.67.220.220
  81. '
  82.  
  83. Level3_servers='
  84. 4.2.2.1
  85. 4.2.2.2
  86. 4.2.2.3
  87. 4.2.2.4
  88. '
  89.  
  90. test_servers "$BSNL_servers" 'Known BSNL DNS servers with query response times'
  91. test_servers "$OpenDNS_servers" 'Known OpenDNS servers with query response times'
  92. test_servers "$Level3_servers" 'Known Level3 servers with query response times'
  93.  
  94. echo '
  95. Here'"'"'s the current /etc/resolv.conf:'
  96. cat '/etc/resolv.conf'
  97. \exit 0
  98.  
RAW Paste Data