023、安全使用:Windows防火墙优化管理 2024-11-11 字数统计: 268字 | 阅读时长≈ 1分 下载链接:firewall.bat 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647@echo off:: 改为 UTF-8显示,防止命令提示符乱码chcp 65001>nullecho 启用Windows防火墙并添加拒绝指定端口的规则...:: 检查是否以管理员权限运行openfiles >nul 2>&1if %errorlevel% neq 0 ( echo 请以管理员权限运行此脚本。 pause exit /b 1):: 启用所有配置文件的Windows防火墙netsh advfirewall set allprofiles state onif %errorlevel% neq 0 ( echo 无法启用Windows防火墙。 pause exit /b 1)echo 规则开始添加call :ADD_RULE "Deny TCP 135" TCP 135 in blockcall :ADD_RULE "Deny TCP 137" TCP 137 in blockcall :ADD_RULE "Deny UDP 137" UDP 137 in blockcall :ADD_RULE "Deny TCP 138" TCP 138 in blockcall :ADD_RULE "Deny UDP 138" UDP 138 in blockcall :ADD_RULE "Deny TCP 139" TCP 139 in blockcall :ADD_RULE "Deny TCP 445" TCP 445 in blockecho 操作完成,请按任意键退出pause >nulexit /b 0:ADD_RULEnetsh advfirewall firewall add rule name=%1 protocol=%2 localport=%3 dir=%4 action=%5 enable=yesif %errorlevel% neq 0 ( echo 无法添加规则: %1 pause exit /b 1)echo Windows防火墙已启用,且已添加%1的规则。goto :EOF:: 结束标签:EOF Windows