Created
January 27, 2026 06:56
-
-
Save symant233/809d4bf76c29ccf4b6f8ddc32a9129f7 to your computer and use it in GitHub Desktop.
RDP protocol ports forwarding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # ==================================================== | |
| # 配置区域 | |
| # ==================================================== | |
| # 目标电脑(被控端)的 IP 地址(如 Tailscale IP 或局域网 IP) | |
| REMOTE_IP="100.100.120.233" | |
| # RDP 默认端口 | |
| RDP_PORT=3389 | |
| # ==================================================== | |
| echo "------------------------------------------" | |
| echo "🔍 正在检测当前设备本地 IP..." | |
| echo "------------------------------------------" | |
| # 显示非 127.0.0.1 和非 Tailscale 的本地局域网 IP | |
| ifconfig | grep "inet " | grep -v "127.0.0.1" | grep -v " 100." | |
| echo "------------------------------------------" | |
| echo "💡 提示:请在远程桌面客户端输入上面显示的本地 IP" | |
| echo "🚀 正在启动 RDP 转发 -> $REMOTE_IP:$RDP_PORT" | |
| echo "------------------------------------------" | |
| # 清理旧的 socat 进程防止冲突 | |
| pkill socat > /dev/null 2>&1 | |
| # 转发 TCP 3389 (核心指令) | |
| socat TCP4-LISTEN:$RDP_PORT,fork,reuseaddr TCP4:$REMOTE_IP:$RDP_PORT & | |
| # 转发 UDP 3389 (可选,用于提升流畅度) | |
| socat UDP4-LISTEN:$RDP_PORT,fork,reuseaddr UDP4:$REMOTE_IP:$RDP_PORT & | |
| echo "✅ RDP 转发服务已启动。" | |
| echo "⚠️ 如果是 Termux,请确保开启了 'Acquire wake lock' 以防后台断开。" | |
| echo "按 Ctrl+C 停止转发" | |
| echo "------------------------------------------" | |
| # 保持脚本运行 | |
| wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment