@echo off
rem 设置指定端口变量和出入站规则名称
set INPUT_RULE_NAME=ZW-IN
set OUT_RULE_NAME=ZW-OUT
set PORT=27700,27701,27702,3316,7998,7999
rem 创建入站规则
echo Input Rule
netsh advfirewall firewall show rule name=%INPUT_RULE_NAME% >nul
rem 如果已经存在则先删除
if not ERRORLEVEL 1 (
netsh advfirewall firewall delete rule name=%INPUT_RULE_NAME% >nul
)
netsh advfirewall firewall add rule name=%INPUT_RULE_NAME% dir=in action=allow protocol=TCP localport=%PORT%
echo %INPUT_RULE_NAME% Create Successed!
pause
rem 创建出站规则
echo Output Rule
netsh advfirewall firewall show rule name=%OUT_RULE_NAME% >nul
rem 如果已经存在则先删除
if not ERRORLEVEL 1 (
netsh advfirewall firewall delete rule name=%OUT_RULE_NAME% >nul
)
netsh advfirewall firewall add rule name=%OUT_RULE_NAME% dir=out action=allow protocol=TCP localport=%PORT%
echo %OUT_RULE_NAME% Create Successed!
echo Done!