bat批处理 添加防火墙出入站规则

akiooo 2023-04-06 PM 719℃ 0条

@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!

非特殊说明,本博所有文章均为博主原创,

部分转载有可能忘记标注,如侵犯了您的权益,您可以留言我增加原文出处或删除文档。

评论啦~