@echo off chcp 65001 >nul 2>&1 title 设备自动化后台(局域网模式) REM ===== 自动提权到管理员 ===== net session >nul 2>&1 if %errorlevel% neq 0 ( echo 需要管理员权限以支持局域网访问,正在提权... powershell -Command "Start-Process -FilePath '%~f0' -Verb RunAs" exit /b ) cd /d "%~dp0" REM ===== 添加防火墙入站规则(放行 Python,仅一次) ===== for /f "delims=" %%i in ('where python') do set PY_EXE=%%i netsh advfirewall firewall show rule name="PlatformTools Web" >nul 2>&1 if %errorlevel% neq 0 ( echo 正在添加防火墙规则... netsh advfirewall firewall add rule name="PlatformTools Web" dir=in action=allow program="%PY_EXE%" enable=yes >nul 2>&1 netsh advfirewall firewall add rule name="PlatformTools Web" dir=out action=allow program="%PY_EXE%" enable=yes >nul 2>&1 ) echo ============================================ echo 管理后台已启动(局域网可访问) echo 本机访问: http://127.0.0.1:5050/ echo 局域网访问: http://本机IP:5050/ echo 默认账号: admin / admin123 echo 按 Ctrl+C 停止 echo ============================================ echo. python web_server.py pause