批处理封闭windows中端口的方法

发布时间:2020-07-31编辑:脚本学堂
本文介绍一个封闭windows某些端口的批处理脚本,有需要的朋友,参考下吧。

以下批处理脚本,可以封闭某些windows中的恶意端口,供大家参考。
代码如下:
 

复制代码 代码示例:
sc query PolicyAgent|find /i "PolicyAgent"
if %errorlevel% == 1 (
   sc create PolicyAgent binpath= "%windir%system32lsass.exe" type= share start= auto displayname= "IPSEC Services" depend= RPCSS/IPSec
)
sc config PolicyAgent start= auto
sc start PolicyAgent Services
ipseccmd   -w REG -p "SUNWARD" -o -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block TCP/135" -f *+0:135:TCP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block TCP/139" -f *+0:139:TCP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block TCP/445" -f *+0:445:TCP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block TCP/1443" -f *+0:1443:TCP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block TCP/1444" -f *+0:1444:TCP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block UDP/135" -f *+0:135:UDP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block UDP/139" -f *+0:139:UDP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block UDP/445" -f *+0:445:UDP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block UDP/1443" -f *+0:1443:UDP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -r "Block UDP/1444" -f *+0:1444:UDP -n BLOCK -x >nul
ipseccmd   -w REG -p "SUNWARD" -x >nul