Advertisement
sergio_educacionit

ping_monintor-v2.sh

Jan 13th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. # medidor de ping
  5. # https://espanol.cox.com/residential/internet/guides/gaming-performance/ping-testing.html}
  6.  
  7. # Menos de 50 ms 'bueno'
  8. # Menos de 100 ms 'regular'
  9. # Menos de 150 ms 'malo'
  10. # Mayor a 150 ms 'sin conexion'
  11.  
  12. # 1 True
  13. # 0 False
  14.  
  15.  
  16. # validar nombre de dominio
  17.  
  18.  
  19. # validar sintaxis de IP
  20.  
  21. #regex_ip='^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  22.  
  23. #[[ $host =~ $regex_ip ]] || exit 1
  24.  
  25. func_host_validator () {
  26.  
  27. if [ "$1" == "h" ];then
  28. host $1 > /dev/null 2>&1 || return 1
  29. return 0
  30. elif [ "$" == "4" ]; then
  31. # codigo para evaluar ip
  32. fi
  33. }
  34.  
  35. tipo=$1
  36. host=$2
  37.  
  38. if func_host_validator $tipo $host; then
  39.  
  40.  
  41. while :; do
  42.  
  43. clear
  44.  
  45. ping=$(ping -c 1 $host | grep "64 bytes from" | cut -d "=" -f 4 | cut -d " " -f 1)
  46.  
  47.  
  48. # si el valor es entero pasarlo a decimal.
  49.  
  50. [[ "$ping" =~ .*$ ]] || ping=${ping}.0
  51.  
  52.  
  53. if [ $(awk 'BEGIN { if ('$ping' > 100.0) print 1; else print 0 }') -eq 1 ] &&
  54. [ $(awk 'BEGIN { if ('$ping' <= 150.0) print 1; else print 0 }') -eq 1 ]; then
  55.  
  56. echo "malo"
  57.  
  58. elif [ $(awk 'BEGIN { if ('$ping' <= 50.0) print 1; else print 0 }') -eq 1 ]; then
  59.  
  60. echo "bueno"
  61.  
  62. elif [ $(awk 'BEGIN { if ('$ping' > 150.0) print 1; else print 0 }') -eq 1 ]; then
  63.  
  64. echo "sin conexion"
  65.  
  66. else
  67. echo "regular"
  68.  
  69. fi
  70.  
  71. sleep 0.5
  72. done
  73.  
  74.  
  75. else
  76. echo "host incorrecto"
  77. exit 1
  78.  
  79. fi
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement