Replace external IP fetching with local system commands

This commit is contained in:
Whispering Wind
2025-03-08 20:21:12 +03:30
committed by GitHub
parent a327436be8
commit 863be6a7cc

View File

@ -73,22 +73,27 @@ load_hysteria2_env() {
} }
load_hysteria2_ips() { load_hysteria2_ips() {
if [ -f "$CONFIG_ENV" ]; then if [ -f "$CONFIG_ENV" ]; then
export $(grep -v '^#' "$CONFIG_ENV" | xargs) export $(grep -v '^#' "$CONFIG_ENV" | xargs)
if [[ -z "$IP4" || -z "$IP6" ]]; then if [[ -z "$IP4" || -z "$IP6" ]]; then
echo "Warning: IP4 or IP6 is not set in configs.env. Fetching from ip.gs..." echo "Warning: IP4 or IP6 is not set in configs.env. Fetching from system..."
IP4=$(curl -s -4 ip.gs) default_interface=$(ip route | grep default | awk '{print $5}')
IP6=$(curl -s -6 ip.gs) IP4=$(ip addr show "$default_interface" | grep "inet " | awk '{print $2}' | cut -d '/' -f 1 | head -n 1)
IP6=$(ip addr show "$default_interface" | grep "inet6 " | awk '{print $2}' | grep -v "^fe80::" | cut -d '/' -f 1 | head -n 1)
fi fi
else else
echo "Error: configs.env file not found. Fetching IPs from ip.gs..." echo "Error: configs.env file not found. Fetching IPs from system..."
IP4=$(curl -s -4 ip.gs) default_interface=$(ip route | grep default | awk '{print $5}')
IP6=$(curl -s -6 ip.gs) IP4=$(ip addr show "$default_interface" | grep "inet " | awk '{print $2}' | cut -d '/' -f 1 | head -n 1)
IP6=$(ip addr show "$default_interface" | grep "inet6 " | awk '{print $2}' | grep -v "^fe80::" | cut -d '/' -f 1 | head -n 1)
fi fi
echo "IP4=$IP4" > "$CONFIG_ENV"
echo "IP6=$IP6" >> "$CONFIG_ENV"
} }
# check_services() { # check_services() {
# # source /etc/hysteria/core/scripts/services_status.sh # # source /etc/hysteria/core/scripts/services_status.sh
# for service in "${services[@]}"; do # for service in "${services[@]}"; do