From f53de57c741fa954579a1daf26fa8674d13b923e Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Mon, 2 Feb 2026 23:55:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EIPv6=E7=9A=84=E8=BD=AC?= =?UTF-8?q?=E5=8F=91=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Forward-Tools/socat_tools.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Forward-Tools/socat_tools.sh b/Forward-Tools/socat_tools.sh index b23ec0f..606308c 100644 --- a/Forward-Tools/socat_tools.sh +++ b/Forward-Tools/socat_tools.sh @@ -87,9 +87,12 @@ create_service() { read -rp "目标端口: " TARGET_PORT echo "协议类型:" - echo "1) TCP" - echo "2) UDP" - read -rp "选择 (1/2): " PROTO_CHOICE + echo "1) TCP (IPv4)" + echo "2) TCP (IPv6)" + echo "3) UDP (IPv4)" + echo "4) UDP (IPv6)" + + read -rp "选择 (1/2/3/4): " PROTO_CHOICE case "$PROTO_CHOICE" in 1) @@ -97,8 +100,16 @@ create_service() { SOCAT_CMD="TCP-LISTEN:${LOCAL_PORT},reuseaddr,fork TCP:${TARGET_IP}:${TARGET_PORT}" ;; 2) + PROTO="tcp6" + SOCAT_CMD="TCP6-LISTEN:${LOCAL_PORT},reuseaddr,fork TCP6:${TARGET_IP}:${TARGET_PORT}" + ;; + 3) PROTO="udp" - SOCAT_CMD="UDP-LISTEN:${LOCAL_PORT},reuseaddr UDP:${TARGET_IP}:${TARGET_PORT}" + SOCAT_CMD="UDP-LISTEN:${LOCAL_PORT},reuseaddr,fork UDP:${TARGET_IP}:${TARGET_PORT}" + ;; + 4) + PROTO="udp6" + SOCAT_CMD="UDP6-LISTEN:${LOCAL_PORT},reuseaddr,fork UDP6:${TARGET_IP}:${TARGET_PORT}" ;; *) echo "❌ 无效选择" @@ -114,6 +125,7 @@ create_service() { Description=Socat ${PROTO^^} Port Forward ${LOCAL_PORT} -> ${TARGET_IP}:${TARGET_PORT} After=network.target + [Service] Type=simple ExecStart=/usr/bin/socat ${SOCAT_CMD}