前言:根据防火墙的规则,所以方便管理防火墙的端口,所以写了一个bat批处理脚本方便管理和控制,易于方便其他不懂防火墙规则的运维人员操作。直接上代码如下:
@echo off
mode con: cols=85 lines=30
rem color脚本颜色
color 0D
cls
echo.----------------------------防火墙设置-----------------------------
echo.
echo -----------------------禁用/启用tcp_udp端口--------------------------
echo.
echo.(1:启用端口 2:禁用端口)
echo.
set start=
set /p start= 请输入(1或者2)后按回车键:
if "%start%"=="1" goto on_WIN2008
if "%start%"=="2" goto off_WIN2008
:on_WIN2008
set port_1=
set /p port_1= 输入(1-65535)端口号后按回车键---启用端口:
if "%port_1%" == "" goto on_win2008
sc config lanmanserver start= disabled
netsh advfirewall set currentprofile state on > nul
rem 添加前删除该端口的所有防火墙限制
netsh advfirewall firewall delete rule name=all protocol=tcp localport="%port_1%" > nul
netsh advfirewall firewall delete rule name=all protocol=udp localport="%port_1%" > nul
netsh advfirewall firewall add rule name="EnableTCP" dir=in action=allow localport="%port_1%" remoteip=any protocol=tcp > nul
netsh advfirewall firewall add rule name="EnableUDP" dir=in action=allow localport="%port_1%" remoteip=any protocol=udp > nul
echo .
echo * 开通端口 %port_1% 命令执行完毕!
echo .
set continue=
echo.
echo.
set /p continue= 继续/退出(任意键/n):
if not "%continue%"=="n" goto on_WIN2008
if "%continue%"=="n" goto exit
pause
:off_WIN2008
set port_1=
set /p port_1= 输入(1-65535)端口号后按回车键---禁用端口:
if "%port_1%" == "" goto off_win2008
sc config lanmanserver start= disabled
netsh advfirewall set currentprofile state on > nul
rem 添加前删除该端口的所有防火墙限制
netsh advfirewall firewall delete rule name=all protocol=tcp localport="%port_1%" > nul
netsh advfirewall firewall delete rule name=all protocol=udp localport="%port_1%" > nul
netsh advfirewall firewall add rule name="DenyEquationTCP" dir=in action=block localport="%port_1%" remoteip=any protocol=tcp > nul
netsh advfirewall firewall add rule name="DenyEquationUDP" dir=in action=block localport="%port_1%" remoteip=any protocol=udp > nul
echo .
echo * 禁用端口 %port_1% 命令执行完毕!
echo .
set continue=
echo.
echo.
set /p continue= 继续/退出(任意键/n):
if not "%continue%"=="n" goto off_WIN2008
if "%continue%"=="n" goto exit
pause
不足之处还请指教,感谢各位博友的支持!
来源:CSDN
作者:qq_38135191
链接:https://blog.csdn.net/qq_38135191/article/details/103459778