fix: optimize ext addr value resolution

This commit is contained in:
libm committed 2025-10-11 14:46:22 +08:00
1 parent 8da89f1d56
commit 0c84b76bb7
2 files changed
+11 -10

No files matched your search

+5 -4
View File
@@ -114,17 +114,18 @@ function clashui() {
# ifconfig.me
local query_url='api64.ipify.org'
local public_ip=$(curl -s --noproxy "*" --connect-timeout 2 $query_url)
local public_address="http://${public_ip:-公网}:${UI_PORT}/ui"
local public_address="http://${public_ip:-公网}:${EXT_PORT}/ui"
# 内网ip
# ip route get 1.1.1.1 | grep -oP 'src \K\S+'
local local_ip=$(hostname -I | awk '{print $1}')
local local_address="http://${local_ip}:${UI_PORT}/ui"
local local_ip=$EXT_IP
[ "$EXT_IP" = '0.0.0.0' ] && local_ip=$(hostname -I | awk '{print $1}')
local local_address="http://${local_ip}:${EXT_PORT}/ui"
printf "\n"
printf "╔═══════════════════════════════════════════════╗\n"
printf "║ %s ║\n" "$(_okcat 'Web 控制台')"
printf "║═══════════════════════════════════════════════║\n"
printf "║ ║\n"
printf "║ 🔓 注意放行端口:%-5s ║\n" "$UI_PORT"
printf "║ 🔓 注意放行端口:%-5s ║\n" "$EXT_PORT"
printf "║ 🏠 内网:%-31s ║\n" "$local_address"
printf "║ 🌏 公网:%-31s ║\n" "$public_address"
printf "║ ☁️ 公共:%-31s ║\n" "$URL_CLASH_UI"
+6 -6
View File
@@ -147,14 +147,14 @@ function _get_proxy_port() {
function _get_ui_port() {
local ext_addr=$(sudo "$BIN_YQ" '.external-controller // ""' $CLASH_CONFIG_RUNTIME)
local ext_port=${ext_addr##*:}
UI_PORT=${ext_port:-9090}
EXT_IP=${ext_addr%%:*}
EXT_PORT=${ext_addr##*:}
_is_already_in_use "$UI_PORT" "$BIN_KERNEL_NAME" && {
_is_already_in_use "$EXT_PORT" "$BIN_KERNEL_NAME" && {
local newPort=$(_get_random_port)
local msg="端口占用:${UI_PORT} 🎲 随机分配:$newPort"
sudo "$BIN_YQ" -i ".external-controller = \"0.0.0.0:$newPort\"" $CLASH_CONFIG_RUNTIME
UI_PORT=$newPort
local msg="端口占用:${EXT_PORT} 🎲 随机分配:$newPort"
sudo "$BIN_YQ" -i ".external-controller = \"$EXT_IP:$newPort\"" $CLASH_CONFIG_RUNTIME
EXT_PORT=$newPort
_failcat '🎯' "$msg"
}
}