Hola al foro
Quiero presentarles un pequeño script que he desarrollado para chequear la conexión de área local, es decir, la conexión hasta el router, los DNS y la resolución de nombres. Debido a varios problemillas que he tenido con los DNS se me ocurrio crear el script. Lo muestro aqui por si alguien le interesa...
Un saludo, Brixton CatCódigo:#!/bin/bash # # SCRIPT TO CHECK YOURS CONECTIONS # function net { ipl=`ifconfig | grep -E "inet[^6]" | grep -v 127 | awk '{print $2}' | sed s/[a-zA-Z:]*//` msk=`ifconfig | grep -E "inet[^6]" | grep -v 127 | awk '{print $4}' | sed s/[a-zA-Z:]*//` gtw=`route | grep default | awk '{print $2}'` int=`route | grep default | awk '{print $8}'` dns1=`cat /etc/resolv.conf | grep -v "#" | grep -n "" | grep "1:" | awk '{print $2}'` dns2=`cat /etc/resolv.conf | grep -v "#" | grep -n "" | grep "2:" | awk '{print $2}'` } # function conect { for i in $ipr; do ping -c 1 $i > temp ip=`cat temp | grep -oE "PING [0-9.]+" | awk '{print $2}'` env=`cat temp | grep -oE "[0-9]+ packets transmitted" | awk '{print $1}'` rec=`cat temp | grep -oE "[0-9]+ received" | awk '{print $1}'` per=`cat temp | grep -oE "[0-9]+% packet loss" | awk '{print $1}'` los=`expr $env - $rec` echo -e "IP destino: $ip" echo -e "Paquetes enviados: $env" echo -e "Paquetes recibidos: $rec" echo -e "Paquetes perdidos: $los" echo -e "Perdidas: $per" if [[ `cat temp | grep -oE "[0-9]+% packet loss" | awk '{print $1}' | sed s/\%//` == 0 ]]; then echo -e OK else echo -e OPS! fi echo -e "-----------------------" done } # net echo -ne "Creo que esta es tu configuracion de red:\n\tInterfaz: $int\n\tIP: $ipl\n\tMascara: $msk\n\tGateway: $gtw\n\tDNS 1: $dns1\n\tDNS 2: $dns2\nEs correcto (s/n): " read resp if [[ $resp == s || $resp == S ]]; then ipr=`echo "$ipl $gtw $dns1 $dns2"` elif [[ $resp == n || $resp == N ]]; then echo -e "Hasta otra..." exit 1 else echo -e "Debes responder si o no... vuelve a internarlo ;)" exit 1 fi clear echo -e "Probando conectividad..." conect > temp2 echo -ne "RESULTADOS:\n-----------\n\t1) $int\n\t2) $gtw\n\t3) $dns1\n\t4) $dns2\n\t*) Cualquier otra tecla para verlos todos\nElige el numero asociado al resultado que quieras ver: " read report case $report in 1) clear cat temp2 | grep -A 5 `echo $ipl` ;; 2) clear cat temp2 | grep -A 5 `echo $gtw` ;; 3) clear cat temp2 | grep -A 5 `echo $dns1` ;; 4) clear cat temp2 | grep -A 5 `echo $dns2` ;; *) clear more temp2 ;; esac echo -e "\nQuieres probar la resolucion de nombres?\nEscribe la pagina web con la que quieras comprobar los servidores DNS\n[www.google.es]" read resp if [ -z $resp ]; then ping -c 1 www.google.es > temp elif [ $resp = `echo $resp | grep -oE "www\.[a-z.]+\.[a-z.][a-z.]+"` ]; then ping -c 1 $resp > temp else ping -c 1 www.google.es > temp fi echo -e "Ping a: `cat temp | grep -oE "PING www\.[a-z.]+\.[a-z.][a-z.]+" | awk '{print $2}'`" echo -e "Perdidas: `cat temp | grep -oE "[0-9]+% packet loss" | awk '{print $1}'`" if [[ `cat temp | grep -oE "[0-9]+% packet loss" | awk '{print $1}' | sed s/\%//` == 0 ]]; then echo -e OK else echo -e OPS! fi rm -rf temp* exit 0 # #End
Marcadores