This commit is contained in:
Olia Lisa
2026-05-21 16:22:44 +08:00
parent 2e1f9b0e96
commit 56202723c7
+3 -13
View File
@@ -166,30 +166,20 @@ port_manage() {
# ==========================================
# 更新 sing-box 配置文件中的监听端口,并开放对应防火墙规则
# 参数1: 端口号(可选,不传则在指定范围内随机选取空闲端口)
# 参数2: 随机端口起始值(可选,默认 5000)
# 参数3: 随机端口结束值(可选,默认 15000)
# 参数: 端口号(可选,不传则设置一个5000 到 15000的空闲端口)
# --- 使用示例 ---
# 指定端口
# update_port 8080
#
# 自动随机端口(默认范围 5000-15000)
# update_port
#
# 自动随机端口(自定义范围)
# update_port "" 20000 30000
# ==========================================
update_port(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_dir="$script_dir/../config"
local port=$1
# 如果没有提供端口参数,则自动查找一个随机空闲端口
if [[ -z "$port" ]]; then
port=$(find_free_port 5000 15000)
fi
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件夹绝对路径
local config_dir="$script_dir/../config"
modify_json_file "$config_dir/config.json" ".inbounds[0].listen_port" "$port"
port_manage allow "$port"
echo "设置端口成功"