Files
nxxmdata/backend/configure-firewall.bat
2025-09-12 20:08:42 +08:00

62 lines
1.8 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
echo 正在配置Windows防火墙以允许外部访问...
echo.
REM 检查是否以管理员身份运行
net session >nul 2>&1
if %errorLevel% == 0 (
echo 检测到管理员权限,继续配置...
) else (
echo 错误:请以管理员身份运行此脚本
echo 右键点击此文件,选择"以管理员身份运行"
pause
exit /b 1
)
echo.
echo 添加防火墙规则...
REM 允许前端端口5300
netsh advfirewall firewall add rule name="Node.js Frontend Port 5300" dir=in action=allow protocol=TCP localport=5300
if %errorLevel% == 0 (
echo ✅ 前端端口5300规则添加成功
) else (
echo ⚠️ 前端端口5300规则可能已存在
)
REM 允许后端端口5350
netsh advfirewall firewall add rule name="Node.js Backend Port 5350" dir=in action=allow protocol=TCP localport=5350
if %errorLevel% == 0 (
echo ✅ 后端端口5350规则添加成功
) else (
echo ⚠️ 后端端口5350规则可能已存在
)
REM 允许Node.js程序
netsh advfirewall firewall add rule name="Node.js Program" dir=in action=allow program="C:\Program Files\nodejs\node.exe" enable=yes
if %errorLevel% == 0 (
echo ✅ Node.js程序规则添加成功
) else (
echo ⚠️ Node.js程序规则可能已存在
)
echo.
echo 检查已添加的规则...
netsh advfirewall firewall show rule name="Node.js Frontend Port 5300"
echo.
netsh advfirewall firewall show rule name="Node.js Backend Port 5350"
echo.
echo 🎉 防火墙配置完成!
echo.
echo 现在其他用户可以通过以下地址访问您的服务:
echo 前端: http://172.28.112.1:5300
echo 后端: http://172.28.112.1:5350
echo.
echo 请确保:
echo 1. 服务器正在运行
echo 2. 其他用户与您在同一个局域网内
echo 3. 使用正确的IP地址不是localhost
echo.
pause