一、防火墙 | @echo off | | | | sc config sharedaccess start= auto | | | | | | | | | | rem blockinbound,blockoutbound,allowinbound,allowoutbound | | netsh advfirewall set allprofiles state on | | netsh advfirewall set allprofiles firewallpolicy allowinbound,allowoutbound | | call:blockport 445 | | call:blockport 135 | | call:blockport 139 | | | | pause >nul &exit | | | | rem 如果不起作用,则重置防火墙 | | netsh firewall reset | | | | rem 关闭端口 | | :blockport | | set port=%1 | | call:clearrule %port% | | netsh advfirewall firewall add rule name="deny tcp %port%" dir=in protocol=tcp localport=%port% action=block | | netsh advfirewall firewall add rule name="deny udp %port%" dir=in protocol=udp localport=%port% action=block | | goto :eof | | | | | | rem 开启端口 | | :openport | | set port=%1 | | call:clearrule %port% | | netsh advfirewall firewall add rule name="allow tcp %port%" dir=in protocol=tcp localport=%port% action=allow | | netsh advfirewall firewall add rule name="allow udp %port%" dir=in protocol=udp localport=%port% action=allow | | goto :eof | | | | rem 清除多余规则 | | :clearrule | | set port=%1 | | netsh advfirewall firewall delete rule name="allow tcp %port%" protocol=tcp localport=%port% >nul | | netsh advfirewall firewall delete rule name="deny tcp %port%" protocol=tcp localport=%port% >nul | | netsh advfirewall firewall delete rule name="allow udp %port%" protocol=udp localport=%port% >nul | | netsh advfirewall firewall delete rule name="deny udp %port%" protocol=udp localport=%port% >nul | | goto :eofCOPY |
------------------------------------------------------------------------------------------------------------------------------------------------
二、组策略 | @echo off | | | | | | | | | | | | | | | | | | | | | | sc config PolicyAgent start= auto | | net start PolicyAgent | | | | call:blockport 445 | | call:blockport 135 | | call:blockport 139 | | rem call:blockping | | rem call:openping | | gpupdate/force | | pause&exit | | | | :blockport | | rem 所有的封端口操作只能写成一个组策略BlockPort,不能135一个,445一个 | | set port=%1 | | ipseccmd -w REG -p BlockPort -r "Block TCP/%port%" -f *+0:%port%:TCP -n BLOCK | | ipseccmd -w REG -p BlockPort -r "Block UDP/%port%" -f *+0:%port%:UDP -n BLOCK | | ipseccmd -w REG -p BlockPort -x | | goto :eof | | | | :blockping | | ipseccmd -w REG -p "BlockPing" -r "Block ping" -f 0+*::ICMP -n BLOCK | | ipseccmd -w REG -p "BlockPing" -x | | goto :eof | | | | :openping | | ipseccmd -w REG -p "BlockPing" -y | | goto :eof | | | | :deletePing | | ipseccmd -w REG -p "BlockPing" -y | | ipseccmd -w REG -p "BlockPing" -o | | goto :eofCOPY |
|