From 078fc195c0af29d513a0f414b4e9316596fdc28e Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Thu, 21 May 2026 18:13:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/port.sh | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/bin/port.sh b/bin/port.sh index 9404481..c3ccdb6 100644 --- a/bin/port.sh +++ b/bin/port.sh @@ -1,5 +1,26 @@ #!/bin/bash +# ========================================== +# 更新 sing-box 配置文件中的监听端口,并开放对应防火墙规则 +# 参数: 端口号(可选,不传则设置一个5000 到 15000的空闲端口) +# --- 使用示例 --- +# 指定端口 +# update_port 8080 +# ========================================== +update_port(){ + 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 "设置端口成功" +} + # 查找随机空闲端口 # 用途: # 在指定端口范围内,随机选择一个当前未被监听(TCP/UDP)的端口 @@ -164,27 +185,6 @@ port_manage() { echo "[OK] SELinux 端口权限已更新 ($ACTION)" } -# ========================================== -# 更新 sing-box 配置文件中的监听端口,并开放对应防火墙规则 -# 参数: 端口号(可选,不传则设置一个5000 到 15000的空闲端口) -# --- 使用示例 --- -# 指定端口 -# update_port 8080 -# ========================================== -update_port(){ - 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 "设置端口成功" -} - # 通过交互方式更新端口 ask_update_port(){ local SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"