使用批处理添加多个防火墙规则

时间:2016-01-03 02:35:22

标签: windows batch-file windows-firewall

我一直在寻找网络间的解决方案来解决我的问题。我有一堆测试应用程序需要设置为LAN ACCESS而不是使用Windows 7防火墙的INTERNET ACCESS。虽然,我可以手动完成,但这将是非常耗时的。

我找到了Charles先生的批处理文件 - 但它阻止了我的应用程序的LAN访问

@echo off
REM      BATCH FILE CREATED BY CHARLES DE HAVILLAND 20/02/2012, v2 08/09/2015
REM  https://sites.google.com/site/mytools4000/home/allow-block-multiple-programs-through-windows-7-firewall
cls
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
 set "DEL=%%a"
 )
 If "%1"=="" GOTO :norulename
  SET RULENAME=%1
 ECHO.
 ECHO.
 ECHO Add 'In AND Out' Firewall rules to all 
 call :ColorText 0b "*.exe ^& *.dll"
 ECHO files in,
 ECHO.
 ECHO   %CD% (inc subfolders)
 ECHO.
 ECHO   "%RULENAME%" Firewall rule name will be used ?
 ECHO.
 ECHO.
 ECHO.
 ECHO press CTRL+C to stop now or
 pause
 cls
 Echo.
 FOR /r %%G in ("*.exe") Do (@echo %%G
 NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=in    program="%%G" action="block" enable="yes")
 FOR /r %%G in ("*.exe") Do (@echo %%G
 NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=out program="%%G" action="block" enable="yes")
 FOR /r %%G in ("*.dll") Do (@echo %%G
 NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=in program="%%G" action="block" enable="yes")
 FOR /r %%G in ("*.dll") Do (@echo %%G
 NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=out program="%%G" action="block" enable="yes")
 Echo.
 Echo done.
 GOTO :Finish

 :norulename
 for %%* in (.) do set RULENAME=%%~nx*
 ECHO.
 ECHO Add 'In AND Out' Firewall rules to all 
 call :ColorText 0b "*.exe ^& *.dll"
 ECHO files in,
 ECHO   %CD% (inc subfolders)
 ECHO.
 ECHO   "%RULENAME%" Firewall rule name will be used ?
 ECHO.
 ECHO.
 ECHO.
 ECHO press CTRL+C to stop now or
 pause
 cls
 Echo.
 REM FOR /r %%G in ("*.exe") Do (@echo %%G
 REM NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=in program="%%G" action="block" enable="yes")
 REM FOR /r %%G in ("*.exe") Do (@echo %%G
 REM NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=out program="%%G" action="block" enable="yes")
 REM FOR /r %%G in ("*.dll") Do (@echo %%G
 REM NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=in program="%%G" action="block" enable="yes")
REM FOR /r %%G in ("*.dll") Do (@echo %%G
REM NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=out program="%%G" action="block" enable="yes")
Echo.
Echo done.

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1

:Finish
Echo.
Echo.
Echo Batch ended...

这是一个非常有用的批处理应用程序。但我需要将其修改为仅允许LOCAL / LAN访问应用程序和DENY Internet Access。你能帮助我吗?

OS:WINDOWS 7 ULTIMATE 32Bit

0 个答案:

没有答案