Files
DynastyRevolution-Scripts/modules/network

197 lines
7.2 KiB
Bash

#!/bin/bash
# DYNR Module: Network Diagnostics
run_network() {
BLUE='\033[38;5;45m'; PURPLE='\033[38;5;127m'; GOLD='\033[38;5;178m'; RED='\033[38;5;196m'; NC='\033[0m'
# --- 1. Pre-emptive Check (Cloudflare) ---
echo -e "${BLUE}🐉 Scanning the ether via Cloudflare...${NC}"
if ping -c 1 -W 1 1.1.1.1 &>/dev/null; then
ONLINE=true
else
ONLINE=false
echo -e "${RED}⚠️ Warning: No internet connectivity detected.${NC}"
echo -e "Would you like to attempt a Network Restoration? (y/n)"
read -p "> " choice < /dev/tty
if [[ "$choice" == "y" ]]; then
sudo dhclient -r && sudo dhclient
sleep 2
# Re-check after restoration
ping -c 1 -W 1 1.1.1.1 &>/dev/null && ONLINE=true
fi
fi
# --- 2. Data Retrieval ---
get_status() {
LOCAL_IP=$(hostname -I | awk '{print $1}')
GATEWAY=$(ip route | grep default | awk '{print $3}')
# Only attempt external IP if Cloudflare check passed
if [ "$ONLINE" = true ]; then
EXTERNAL_IP=$(curl -s --connect-timeout 2 https://ifconfig.me || echo "OFFLINE")
else
EXTERNAL_IP="OFFLINE"
fi
}
show_header() {
clear
echo -e "${PURPLE}=================================================${NC}"
echo -e "${BLUE} 🐉 DYNASTY REVOLUTION: NETWORK 🐉 ${NC}"
echo -e "${PURPLE}=================================================${NC}"
get_status
echo -e "${GOLD}LOCAL IP: ${NC}$LOCAL_IP"
echo -e "${GOLD}GATEWAY: ${NC}$GATEWAY"
echo -e "${GOLD}EXTERNAL IP: ${NC}$EXTERNAL_IP"
echo -e "${PURPLE}=================================================${NC}"
}
show_header
# --- 3. Menu ---
echo -e "${BLUE}Main Menu:${NC}"
echo "1) Ping Test (Select Server)"
echo "2) Network Restoration (dhclient refresh)"
echo "3) Show Interfaces"
echo "4) Return"
read -p "Selection [1-4]: " NET_OPT < /dev/tty
case $NET_OPT in
1)
echo -e "\n${BLUE}Select target to ping:${NC}"
options=("Cloudflare (1.1.1.1)" "Quad9 (9.9.9.9)" "OpenDNS (208.67.222.222)" "Google (8.8.8.8)" "All Servers" "Back")
select dns_opt in "${options[@]}"; do
case $dns_opt in
"Cloudflare (1.1.1.1)") targets=("1.1.1.1"); break;;
"Quad9 (9.9.9.9)") targets=("9.9.9.9"); break;;
"OpenDNS (208.67.222.222)") targets=("208.67.222.222"); break;;
"Google (8.8.8.8)") targets=("8.8.8.8"); break;;
"All Servers") targets=("1.1.1.1" "9.9.9.9" "208.67.222.222" "8.8.8.8"); break;;
"Back") run_network; return;;
esac
done
for ip in "${targets[@]}"; do
echo -ne "${GOLD}Pinging $ip... ${NC}"
if ping -c 3 -W 2 "$ip" &>/dev/null; then
echo -e "${BLUE}ONLINE ✨${NC}"
else
echo -e "${RED}OFFLINE ❌${NC}"
fi
done
read -p "Press Enter to return..." < /dev/tty
run_network
;;
2)
echo -e "${GOLD}🐉 Re-initializing Network Leases...${NC}"
sudo dhclient -r && sudo dhclient
echo -e "${BLUE}Restoration complete. Refreshing status...${NC}"
sleep 2
run_network
;;
3)
ip -br addr show
read -p "Press Enter to return..." < /dev/tty
run_network
;;
*) return ;;
esac
}#!/bin/bash
# DYNR Module: Network Diagnostics
run_network() {
BLUE='\033[38;5;45m'; PURPLE='\033[38;5;127m'; GOLD='\033[38;5;178m'; RED='\033[38;5;196m'; NC='\033[0m'
# --- 1. Pre-emptive Check (Cloudflare) ---
echo -e "${BLUE}🐉 Scanning the ether via Cloudflare...${NC}"
if ping -c 1 -W 1 1.1.1.1 &>/dev/null; then
ONLINE=true
else
ONLINE=false
echo -e "${RED}⚠️ Warning: No internet connectivity detected.${NC}"
echo -e "Would you like to attempt a Network Restoration? (y/n)"
read -p "> " choice < /dev/tty
if [[ "$choice" == "y" ]]; then
sudo dhclient -r && sudo dhclient
sleep 2
# Re-check after restoration
ping -c 1 -W 1 1.1.1.1 &>/dev/null && ONLINE=true
fi
fi
# --- 2. Data Retrieval ---
get_status() {
LOCAL_IP=$(hostname -I | awk '{print $1}')
GATEWAY=$(ip route | grep default | awk '{print $3}')
# Only attempt external IP if Cloudflare check passed
if [ "$ONLINE" = true ]; then
EXTERNAL_IP=$(curl -s --connect-timeout 2 https://ifconfig.me || echo "OFFLINE")
else
EXTERNAL_IP="OFFLINE"
fi
}
show_header() {
clear
echo -e "${PURPLE}=================================================${NC}"
echo -e "${BLUE} 🐉 DYNASTY REVOLUTION: NETWORK 🐉 ${NC}"
echo -e "${PURPLE}=================================================${NC}"
get_status
echo -e "${GOLD}LOCAL IP: ${NC}$LOCAL_IP"
echo -e "${GOLD}GATEWAY: ${NC}$GATEWAY"
echo -e "${GOLD}EXTERNAL IP: ${NC}$EXTERNAL_IP"
echo -e "${PURPLE}=================================================${NC}"
}
show_header
# --- 3. Menu ---
echo -e "${BLUE}Main Menu:${NC}"
echo "1) Ping Test (Select Server)"
echo "2) Network Restoration (dhclient refresh)"
echo "3) Show Interfaces"
echo "4) Return"
read -p "Selection [1-4]: " NET_OPT < /dev/tty
case $NET_OPT in
1)
echo -e "\n${BLUE}Select target to ping:${NC}"
options=("Cloudflare (1.1.1.1)" "Quad9 (9.9.9.9)" "OpenDNS (208.67.222.222)" "Google (8.8.8.8)" "All Servers" "Back")
select dns_opt in "${options[@]}"; do
case $dns_opt in
"Cloudflare (1.1.1.1)") targets=("1.1.1.1"); break;;
"Quad9 (9.9.9.9)") targets=("9.9.9.9"); break;;
"OpenDNS (208.67.222.222)") targets=("208.67.222.222"); break;;
"Google (8.8.8.8)") targets=("8.8.8.8"); break;;
"All Servers") targets=("1.1.1.1" "9.9.9.9" "208.67.222.222" "8.8.8.8"); break;;
"Back") run_network; return;;
esac
done
for ip in "${targets[@]}"; do
echo -ne "${GOLD}Pinging $ip... ${NC}"
if ping -c 3 -W 2 "$ip" &>/dev/null; then
echo -e "${BLUE}ONLINE ✨${NC}"
else
echo -e "${RED}OFFLINE ❌${NC}"
fi
done
read -p "Press Enter to return..." < /dev/tty
run_network
;;
2)
echo -e "${GOLD}🐉 Re-initializing Network Leases...${NC}"
sudo dhclient -r && sudo dhclient
echo -e "${BLUE}Restoration complete. Refreshing status...${NC}"
sleep 2
run_network
;;
3)
ip -br addr show
read -p "Press Enter to return..." < /dev/tty
run_network
;;
*) return ;;
esac
}