Small sh "framework" to test some server responses
sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

net.sh 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #Copyright (C) 2016,2023 Weber Yann
  2. #
  3. #This program is free software; you can redistribute it and/or modify
  4. #it under the terms of the GNU General Public License as published by
  5. #the Free Software Foundation; either version 3 of the License, or
  6. #any later version.
  7. #
  8. #This program is distributed in the hope that it will be useful,
  9. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. #GNU General Public License for more details.
  12. #
  13. #You should have received a copy of the GNU General Public License
  14. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. _check_ping() {
  16. expt=$1
  17. hostname=$2
  18. proto=$3
  19. count=$4
  20. case "$proto" in
  21. ipv4)
  22. protoping="ping -4";;
  23. ipv6)
  24. protoping="ping -6";;
  25. *)
  26. protoping="ping";;
  27. esac
  28. if [ -z "$count" ]
  29. then
  30. count=5
  31. fi
  32. if $protoping -i 0.2 -c "$count" "$hostname" >/dev/null
  33. then
  34. if [ "$expt" = "ping" ]
  35. then
  36. success "successfully send $count ping $proto to '$hostname'"
  37. else
  38. fail "$hostname replied to $count ping $proto"
  39. fi
  40. else
  41. if [ "$expt" = "ping" ]
  42. then
  43. fail "unable to ping '$hostname'"
  44. else
  45. success "unable to ping '$hostname'"
  46. fi
  47. fi
  48. }
  49. check_ping() {
  50. _check_ping "ping" "$1" "$2" "$3" "$4"
  51. }
  52. check_noping() {
  53. _check_ping "noping" "$1" "$2" "$3" "$4"
  54. }
  55. check_dns() {
  56. hostname=$1
  57. field=$2
  58. expt=$3
  59. result=$(dig +short "$hostname" "$field")
  60. if echo "$result" | grep -e "$expt" >/dev/null
  61. then
  62. success "DNS replied '$expt' for '$field $hostname'"
  63. else
  64. fail "Unexpected DNS reply '$result' expecting '$expt' for '$hostname $field'"
  65. fi
  66. }