Update pruebaRed.sh

This commit is contained in:
Manuel Vergara 2024-02-07 00:13:40 +01:00
parent 30bdac305d
commit a02991c150

View File

@ -62,9 +62,9 @@ print_network_table() {
# Comprobación de dependencias # Comprobación de dependencias
check_dependencies() { check_dependencies() {
command -v jq >/dev/null 2>&1 || { echo >&2 "${COLOR_RED}jq no está instalado. Instálalo con 'sudo apt-get install jq'${COLOR_RESET}"; exit 1; } for cmd in "jq" "nordvpn" "speedtest"; do
command -v nordvpn >/dev/null 2>&1 || { echo >&2 "${COLOR_RED}nordvpn no está instalado. Instálalo con 'sudo apt-get install nordvpn'${COLOR_RESET}"; exit 1; } command -v "$cmd" >/dev/null 2>&1 || { echo >&2 "${COLOR_RED}$cmd no está instalado. Instálalo con 'sudo apt-get install $cmd'${COLOR_RESET}"; exit 1; }
command -v speedtest >/dev/null 2>&1 || { echo >&2 "${COLOR_RED}speedtest no está instalado. Instálalo con 'sudo apt-get install speedtest-cli'${COLOR_RESET}"; exit 1; } done
} }
# Función para obtener la IP del router # Función para obtener la IP del router
@ -77,67 +77,123 @@ get_router_ip() {
network_info=() network_info=()
# Comprobar conexión # Comprobar conexión
print_title "COMPROBAR CONEXIÓN" check_connection() {
if ping -c 1 -W 2 8.8.8.8 > /dev/null 2>&1; then print_title "COMPROBAR CONEXIÓN"
echo -e "\t${COLOR_GREEN}Conexión exitosa con 8.8.8.8${COLOR_RESET}" if ping -c 1 -W 2 8.8.8.8 > /dev/null 2>&1; then
else echo -e "\t${COLOR_GREEN}Conexión exitosa con 8.8.8.8${COLOR_RESET}"
echo -e "\t${COLOR_RED}Error de conexión con 8.8.8.8${COLOR_RESET}"
# Obtener la interfaz predeterminada
default_interface=$(ip route show default | awk '/default/ {print $5}')
# Probar la conexión con el router
router_ip=$(get_router_ip "$default_interface")
if ping -c 1 -W 2 "$router_ip" > /dev/null 2>&1; then
echo -e "\t${COLOR_GREEN}Conexión exitosa con el router ($router_ip)${COLOR_RESET}"
else else
echo -e "\t${COLOR_RED}Error de conexión con el router ($router_ip)${COLOR_RESET}" echo -e "\t${COLOR_RED}Error de conexión con 8.8.8.8${COLOR_RESET}"
exit 1 # Agregar la instrucción exit para detener el script
fi # Obtener la interfaz predeterminada
fi default_interface=$(ip route show default | awk '/default/ {print $5}')
# Probar la conexión con el router
# Lista de sitios web a comprobar router_ip=$(get_router_ip "$default_interface")
websites=("vergaracarmona.es" "gitea.vergaracarmona.es" "diariosenderista.es" "marialuisasefardi.es" "prefapp.es") if ping -c 1 -W 2 "$router_ip" > /dev/null 2>&1; then
echo -e "\t${COLOR_GREEN}Conexión exitosa con el router ($router_ip)${COLOR_RESET}"
# Verificar el estado de sitios web else
print_title "VERIFICANDO ESTADO DE WEBS" echo -e "\t${COLOR_RED}Error de conexión con el router ($router_ip)${COLOR_RESET}"
check_website_status() { exit
local website=$1 fi
if ping -c 1 -W 2 "$website" > /dev/null 2>&1; then
echo -e "\t${COLOR_GREEN}$website está levantado${COLOR_RESET}"
else
echo -e "\t${COLOR_RED}$website está caído${COLOR_RESET}"
fi fi
} }
# Iterar sobre la lista de sitios web # Comprobar estado de sitios web
for site in "${websites[@]}"; do check_websites() {
check_website_status "$site" # Lista de sitios web a comprobar
done websites=("vergaracarmona.es" "gitea.vergaracarmona.es" "diariosenderista.es" "marialuisasefardi.es" "prefapp.es")
# Mostrar información de tarjetas de red # Verificar el estado de sitios web
print_title "TARJETAS DE RED" print_title "VERIFICANDO ESTADO DE WEBS"
while read -r interface; do check_website_status() {
network_info+=("$(print_network_info "$interface")") local website=$1
done < <(ip -o link show | awk -F': ' '{print $2}') local timeout=5
local http_code=$(curl -o /dev/null -L -s -w "%{http_code}" --max-time "$timeout" "$website")
# Mostrar la tabla de información de red if [ "$http_code" -eq 200 ]; then
print_network_table echo -e "\t${COLOR_GREEN}$website está levantado. ${COLOR_RESET}"
else
echo -e "\t${COLOR_RED}$website está caído (Código $http_code)${COLOR_RESET}"
fi
}
# Mostrar información de IP WAN # Iterar sobre la lista de sitios web
print_title "INFO IP WAN" for site in "${websites[@]}"; do
curl -s https://ipinfo.io | jq check_website_status "$site"
done
}
# Mostrar estado de NordVPN
print_title "ESTADO NORDVPN"
nordvpn status | grep -v "New feature"
# Realizar test de velocidad # Obtener las interfaces de red
print_title "TEST DE VELOCIDAD" get_interfaces() {
speedtest print_title "TARJETAS DE RED"
while read -r interface; do
network_info+=("$(print_network_info "$interface")")
done < <(ip -o link show | awk -F': ' '{print $2}')
print_network_table
}
# Obtener IP pública
get_public_ip_info() {
print_title "INFO IP WAN"
curl -s https://ipinfo.io | jq -r 'to_entries[] | "\u001b[34m\(.key):\u001b[0m \u001b[32m\(.value)\u001b[0m"'
}
# Estado de nordvpn
nordvpn_status() {
print_title "ESTADO NORDVPN"
nordvpn status | grep -v "New feature"
}
# Test de velocidad
speed_test() {
print_title "TEST DE VELOCIDAD"
speedtest
}
# Realizar traceroute # Realizar traceroute
print_title "TRACEROUTE" traceroute(){
mtr -c 3 -n -r 8.8.8.8 print_title "TRACEROUTE"
mtr -c 3 -n -r 8.8.8.8
}
# Menú principal
main_menu() {
while true; do
print_title "Menú"
echo "1 - Comprobar conexión"
echo "2 - Verificar estado de webs"
echo "3 - Ver tarjetas de red"
echo "4 - Información de IP pública"
echo "5 - Estado de NordVPN"
echo "6 - Test de velocidad"
echo "7 - Traceroute"
echo "8 - Salir"
read -p "Ingrese el número de la opción deseada: " choice
case $choice in
1) check_connection ;;
2) check_websites ;;
3) get_interfaces ;;
4) get_public_ip_info ;;
5) nordvpn_status ;;
6) speed_test ;;
7) traceroute ;;
8) echo -e "${COLOR_RED}\nSaliendo...\n${COLOR_RESET}"; tput cnorm; exit 0 ;;
*) echo -e "${COLOR_RED}\nOpción inválida. Inténtelo de nuevo.${COLOR_RESET}" ;;
esac
done
}
# Función principal
main() {
check_connection
check_websites
get_interfaces
get_public_ip_info
nordvpn_status
main_menu
}
main