添加防火墙规则语句:
netsh advfirewall firewall add rule name="name" dir=out或者in(是在入栈规则还是出栈规则) remoteip="%要访问的IP%" remoteport=需要访问的端口 protocol=UDP或TCP、ICMP等 action=allow或者deny
案例1:允许在出栈放行访问1.1.1.1的UDP600-6010、123等端口
netsh advfirewall firewall add rule name=test1 dir=out remoteip="%1.1.1.1%" remoteport=6000-6010,123,161-162,177 protocol=UDP action=allow >nul
添加防火墙删除案例语句:
netsh advfirewall firewall delete rule name=规则名称使用all代表所有队则 dir=out >nul
案例2:删除所有的出栈规则
netsh advfirewall firewall delete rule name=all dir=out >nul
案例3:终端用户自己定义要访问的IP(通过将输入的IP传递个某个定义的参数,然后再规则应用参数)
案例语句:
@echo ---------------------------------------------------------------
set /p str=请输入IP地址段范围:
@echo ---------------------------------------------------------------
netsh advfirewall firewall add rule name="test1" dir=out remoteip="%str%" remoteport=6000-6010,123,177 protocol=UDP action=allow >nul
netsh advfirewall firewall add rule name="test2" dir=out remoteip="%str%" remoteport=21-23,30001 protocol=TCP action=allow >nul
netsh advfirewall firewall add rule name="test3" dir=out remoteip="%str%" protocol=ICMPV4 action=allow >nul