Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # medidor de ping
- # https://espanol.cox.com/residential/internet/guides/gaming-performance/ping-testing.html}
- # Menos de 50 ms 'bueno'
- # Menos de 100 ms 'regular'
- # Menos de 150 ms 'malo'
- # Mayor a 150 ms 'sin conexion'
- # 1 True
- # 0 False
- # validar nombre de dominio
- # validar sintaxis de IP
- #regex_ip='^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
- #[[ $host =~ $regex_ip ]] || exit 1
- func_host_validator () {
- if [ "$1" == "h" ];then
- host $1 > /dev/null 2>&1 || return 1
- return 0
- elif [ "$" == "4" ]; then
- # codigo para evaluar ip
- fi
- }
- tipo=$1
- host=$2
- if func_host_validator $tipo $host; then
- while :; do
- clear
- ping=$(ping -c 1 $host | grep "64 bytes from" | cut -d "=" -f 4 | cut -d " " -f 1)
- # si el valor es entero pasarlo a decimal.
- [[ "$ping" =~ .*$ ]] || ping=${ping}.0
- if [ $(awk 'BEGIN { if ('$ping' > 100.0) print 1; else print 0 }') -eq 1 ] &&
- [ $(awk 'BEGIN { if ('$ping' <= 150.0) print 1; else print 0 }') -eq 1 ]; then
- echo "malo"
- elif [ $(awk 'BEGIN { if ('$ping' <= 50.0) print 1; else print 0 }') -eq 1 ]; then
- echo "bueno"
- elif [ $(awk 'BEGIN { if ('$ping' > 150.0) print 1; else print 0 }') -eq 1 ]; then
- echo "sin conexion"
- else
- echo "regular"
- fi
- sleep 0.5
- done
- else
- echo "host incorrecto"
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement