2024-02-22 21:02:37 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Colores
|
|
|
|
COLOR_GREEN='\e[32m'
|
|
|
|
COLOR_RED='\e[31m'
|
|
|
|
COLOR_YELLOW='\e[33m'
|
|
|
|
COLOR_BLUE='\e[34m'
|
|
|
|
COLOR_RESET='\e[0m'
|
|
|
|
|
|
|
|
# Control de salida con Ctrl + C
|
|
|
|
function ctrl_c() {
|
|
|
|
echo -e "${COLOR_RED}\n\n[!] Saliendo... \n${COLOR_RESET}"
|
2024-02-24 00:21:04 +01:00
|
|
|
tput cnorm
|
|
|
|
exit 1
|
2024-02-22 21:02:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Ctrl+C
|
|
|
|
trap ctrl_c SIGINT
|
|
|
|
|
|
|
|
# Títulos
|
|
|
|
function print_title {
|
|
|
|
local title="$1"
|
|
|
|
local title_length=${#title}
|
|
|
|
local total_length=22
|
2024-02-24 00:21:04 +01:00
|
|
|
|
2024-02-22 21:02:37 +01:00
|
|
|
# Calcular el tamaño del margen izquierdo y derecho
|
2024-02-24 00:21:04 +01:00
|
|
|
local margin_length=$(((total_length - title_length - 4) / 2))
|
|
|
|
|
2024-02-22 21:02:37 +01:00
|
|
|
# Asegurarse de que el número total de almohadillas sea siempre 22
|
2024-02-24 00:21:04 +01:00
|
|
|
local left_padding=$((margin_length))
|
|
|
|
local right_padding=$((margin_length + (title_length % 2)))
|
|
|
|
|
2024-02-22 21:02:37 +01:00
|
|
|
echo -e "${COLOR_BLUE}\n$(printf '#%.0s' $(seq 1 $left_padding))#### $title ####$(printf '#%.0s' $(seq 1 $right_padding))\n${COLOR_RESET}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Función para imprimir información de red
|
|
|
|
print_network_info() {
|
|
|
|
local interface=$1
|
|
|
|
local ip_lan_4=$(ip addr show "$interface" | grep 'inet ' | awk '{print $2}')
|
|
|
|
local ip_lan_6=$(ip addr show "$interface" | grep 'inet6' | awk '{print $2}')
|
2024-02-24 00:21:04 +01:00
|
|
|
|
2024-02-22 21:02:37 +01:00
|
|
|
if [ -z "$ip_lan_4" ] && [ -z "$ip_lan_6" ]; then
|
|
|
|
printf "${COLOR_BLUE}|${COLOR_RESET}${COLOR_YELLOW} %-16s ${COLOR_RESET}${COLOR_BLUE}|${COLOR_RESET} ${COLOR_RED}%-35s ${COLOR_RESET}${COLOR_BLUE}|${COLOR_RESET}\n" "$interface" "No tiene"
|
|
|
|
else
|
|
|
|
printf "${COLOR_BLUE}|${COLOR_RESET}${COLOR_YELLOW} %-16s ${COLOR_RESET}${COLOR_BLUE}|${COLOR_RESET} ${COLOR_GREEN}%-35s ${COLOR_RESET}${COLOR_BLUE}|${COLOR_RESET}\n" "$interface" "IPv4: $ip_lan_4"
|
|
|
|
if [ -n "$ip_lan_6" ]; then
|
|
|
|
printf "${COLOR_BLUE}|${COLOR_RESET} %-16s ${COLOR_BLUE}|${COLOR_RESET} ${COLOR_GREEN}%-35s ${COLOR_RESET}${COLOR_BLUE}|${COLOR_RESET}\n" "" "IPv6: $ip_lan_6"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Función para imprimir la tabla de información de red
|
|
|
|
print_network_table() {
|
|
|
|
echo -e "\n${COLOR_BLUE}| Interfaz | IP |${COLOR_RESET}"
|
|
|
|
echo -e "${COLOR_BLUE}| ---------------- | ----------------------------------- |${COLOR_RESET}"
|
|
|
|
|
|
|
|
for row in "${network_info[@]}"; do
|
|
|
|
echo -e "$row"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo -e "${COLOR_BLUE}| ---------------- | ----------------------------------- |${COLOR_RESET}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Comprobación de dependencias
|
|
|
|
check_dependencies() {
|
|
|
|
for cmd in "jq" "nordvpn" "speedtest"; do
|
2024-02-24 00:21:04 +01:00
|
|
|
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
|
|
|
|
}
|
2024-02-22 21:02:37 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Función para obtener la IP del router
|
|
|
|
get_router_ip() {
|
|
|
|
local interface=$1
|
|
|
|
ip route show dev "$interface" | grep default | awk '{print $3}'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Inicializar el array para almacenar información de red
|
|
|
|
network_info=()
|
|
|
|
|
|
|
|
# Comprobar conexión
|
|
|
|
check_connection() {
|
|
|
|
print_title "COMPROBAR CONEXIÓN"
|
2024-02-24 00:21:04 +01:00
|
|
|
if ping -c 1 -W 2 8.8.8.8 >/dev/null 2>&1; then
|
2024-02-22 21:02:37 +01:00
|
|
|
echo -e "\t${COLOR_GREEN}Conexión exitosa con 8.8.8.8${COLOR_RESET}"
|
|
|
|
else
|
|
|
|
echo -e "\t${COLOR_RED}Error de conexión con 8.8.8.8${COLOR_RESET}"
|
2024-02-24 00:21:04 +01:00
|
|
|
|
2024-02-22 21:02:37 +01:00
|
|
|
# Obtener la interfaz predeterminada
|
|
|
|
default_interface=$(ip route show default | awk '/default/ {print $5}')
|
2024-02-24 00:21:04 +01:00
|
|
|
|
2024-02-22 21:02:37 +01:00
|
|
|
# Probar la conexión con el router
|
|
|
|
router_ip=$(get_router_ip "$default_interface")
|
2024-02-24 00:21:04 +01:00
|
|
|
if ping -c 1 -W 2 "$router_ip" >/dev/null 2>&1; then
|
2024-02-22 21:02:37 +01:00
|
|
|
echo -e "\t${COLOR_GREEN}Conexión exitosa con el router ($router_ip)${COLOR_RESET}"
|
|
|
|
else
|
|
|
|
echo -e "\t${COLOR_RED}Error de conexión con el router ($router_ip)${COLOR_RESET}"
|
|
|
|
exit 1ç
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Comprobar estado de sitios web
|
|
|
|
check_websites() {
|
|
|
|
# Lista de sitios web a comprobar
|
|
|
|
websites=("vergaracarmona.es" "gitea.vergaracarmona.es" "diariosenderista.es" "marialuisasefardi.es" "prefapp.es")
|
|
|
|
|
|
|
|
# Verificar el estado de sitios web
|
|
|
|
print_title "VERIFICANDO ESTADO DE WEBS"
|
|
|
|
check_website_status() {
|
|
|
|
local website=$1
|
|
|
|
local timeout=5
|
|
|
|
local http_code=$(curl -o /dev/null -L -s -w "%{http_code}" --max-time "$timeout" "$website")
|
|
|
|
|
|
|
|
if [ "$http_code" -eq 200 ]; then
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
# Iterar sobre la lista de sitios web
|
|
|
|
for site in "${websites[@]}"; do
|
|
|
|
check_website_status "$site"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Obtener las interfaces de red
|
|
|
|
get_interfaces() {
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Nueva conexión nordvpn
|
|
|
|
nordvpn_connect() {
|
2024-02-24 00:21:04 +01:00
|
|
|
print_title "CONECTANDO NORDVPN"
|
|
|
|
nordvpn connect Spain Barcelona
|
2024-02-22 21:02:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Test de velocidad
|
|
|
|
speed_test() {
|
|
|
|
print_title "TEST DE VELOCIDAD"
|
|
|
|
speedtest
|
|
|
|
}
|
|
|
|
|
|
|
|
# Realizar traceroute
|
2024-02-24 00:21:04 +01:00
|
|
|
traceroute() {
|
2024-02-22 21:02:37 +01:00
|
|
|
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 - Conectar Nordvpn"
|
2024-02-24 00:21:04 +01:00
|
|
|
echo "7 - Test de velocidad"
|
2024-02-22 21:02:37 +01:00
|
|
|
echo "8 - Traceroute"
|
|
|
|
echo "9 - Salir"
|
2024-02-24 00:21:04 +01:00
|
|
|
|
2024-02-22 21:02:37 +01:00
|
|
|
read -p "Ingrese el número de la opción deseada: " choice
|
|
|
|
case $choice in
|
2024-02-24 00:21:04 +01:00
|
|
|
1) check_connection ;;
|
|
|
|
2) check_websites ;;
|
|
|
|
3) get_interfaces ;;
|
|
|
|
4) get_public_ip_info ;;
|
|
|
|
5) nordvpn_status ;;
|
|
|
|
6) nordvpn_connect ;;
|
|
|
|
7) speed_test ;;
|
|
|
|
8) traceroute ;;
|
|
|
|
9)
|
|
|
|
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}" ;;
|
2024-02-22 21:02:37 +01:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Función principal
|
|
|
|
main() {
|
|
|
|
check_connection
|
|
|
|
check_websites
|
|
|
|
get_interfaces
|
|
|
|
get_public_ip_info
|
|
|
|
nordvpn_status
|
|
|
|
main_menu
|
|
|
|
}
|
|
|
|
|
|
|
|
main
|