1. 添加启动脚本:setproxy.bat
@
echo off
setlocal enabledelayedexpansion
for /f "tokens=2 delims=:" %%i in ('cmd /c "ipconfig | findstr /i /c:"默认网关" /c:"Default Gateway" | findstr /r "[0-9]\.[0-9]""') do (
set GATEWAY_IP=%%i
)
set "GATEWAY_IP=%GATEWAY_IP: =%"
:proxy_set
if not defined GATEWAY_IP (
echo 错误:未找到有效的网关 IP 地址
pause
exit /b 1
)
netsh interface portproxy add v4tov4 listenaddress=127.0.0.1 listenport=7890 connectaddress=%GATEWAY_IP% connectport=7890 protocol=tcp
echo 端口转发成功 TCP !GATEWAY_IP!:7890 -^> 127.0.0.1:7890
echo 正在设置代理为 127.0.0.1:7890
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d "127.0.0.1:7890" /f >nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f >nul
echo 代理设置成功!
echo 代理地址: 127.0.0.1:7890
2. wsb 文件配置:
<LogonCommand>
<Command>C:\temp\setup.bat</Command>
</LogonCommand>