自动代理设置
打开 CMD 自动显示:
[FLClash Running]
Proxy: ON
并且支持命令:
proxy on
proxy off
proxy status
整个过程 一步一步做即可,大约 3–5 分钟。
第一步:创建代理脚本
找到你之前的目录,例如:
C:\Tools
新建文件:
proxy.cmd
例如:
C:\Tools\proxy.cmd
把下面代码完整粘进去:
@echo off
set HOST=127.0.0.1
set PORT=7890
if "%1"=="on" goto on
if "%1"=="off" goto off
if "%1"=="status" goto status
goto help
:on
set http_proxy=http://%HOST%:%PORT%
set https_proxy=http://%HOST%:%PORT%
set HTTP_PROXY=http://%HOST%:%PORT%
set HTTPS_PROXY=http://%HOST%:%PORT%
echo Proxy enabled
goto end
:off
set http_proxy=
set https_proxy=
set HTTP_PROXY=
set HTTPS_PROXY=
echo Proxy disabled
goto end
:status
echo ---- Proxy Variables ----
echo http_proxy=%http_proxy%
echo https_proxy=%https_proxy%
echo.
netstat -ano | findstr "LISTENING" | findstr ":%PORT% " >nul
if %errorlevel%==0 (
echo FLClash running on %PORT%
) else (
echo FLClash NOT running
)
goto end
:help
echo.
echo proxy on
echo proxy off
echo proxy status
echo.
:end
保存。
第二步:创建 CMD 启动脚本
再创建一个文件:
cmd_init.cmd
例如:
C:\Tools\cmd_init.cmd
内容:
@echo off
set PORT=7890
REM 检查端口是否被占用
netstat -ano | findstr "LISTENING" | findstr ":%PORT% " >nul
REM 直接测试代理是否可连接
REM curl -x http://127.0.0.1:7890 -I https://www.google.com --max-time 3 >nul 2>nul
REM 检查特定进程
REM tasklist | findstr /i "flclash.exe" >nul
if %errorlevel%==0 (
call proxy on
echo Proxy: ON
) else (
echo Proxy: OFF
)
echo.
第三步:让 CMD 自动执行
打开注册表:
Win + R
regedit
进入:
HKEY_CURRENT_USER
Software
Microsoft
Command Processor
找到或创建:
AutoRun
值填:
C:\Users\你的用户名\cmd_init.cmd
例如:
C:\Tools\cmd_init.cmd
第四步:把 proxy 命令加入 PATH
这样任何 CMD 都可以直接输入 proxy。
打开:
系统 → 环境变量
在 变量 Path 里新增:
C:\Tools\
然后重新打开 CMD。
第五步:测试
打开新的 CMD,你应该看到:
如果 FLClash 开着
[FLClash Running]
Proxy: ON
如果 FLClash 没开
[FLClash Not Running]
Proxy: OFF
第六步:测试命令
在 CMD 输入:
开启代理
proxy on
关闭代理
proxy off
查看状态
proxy status
最终效果
你现在的 CMD 会变成这样:
启动时:
[FLClash Running]
Proxy: ON
平时使用:
proxy on
proxy off
proxy status
开发体验会很好。
6 个帖子 - 5 位参与者