808604 ランダム
 HOME | DIARY | PROFILE 【フォローする】 【ログイン】

さすらいのプログラマ

SETFW.BAT

WindowsXPのファイアウォールをバッチで有効・無効を切り替えるバッチ
@ECHO OFF
REM -----------------------------------------------------------------
REM SETUP FIREWALL BATCH
REM 
REM 2008/10/01 Created.
REM -----------------------------------------------------------------

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

SET _OPMODE_=
IF /I .%1.==.ON. (
  SET _OPMODE_=ENABLE
)
IF /I .%1.==.OFF. (
  SET _OPMODE_=DISABLE
)
IF /I .%1.==.STATUS. (
  SET _OPMODE_=STATUS
)
IF /I .%1.==.enable. (
  SET _OPMODE_=ENABLE
)
IF /I .%1.==.disable. (
  SET _OPMODE_=DISABLE
)
IF .%_OPMODE_%.==.. (
  CALL :USAGE
  EXIT /B
)

CALL :GET_CURRENT_STATUS

IF /I .%_OPMODE_%.==.STATUS. (
  ECHO.firewall current status [%CURRENT_OPMODE%]
  EXIT /B
)

IF /I .%CURRENT_OPMODE%.==.%_OPMODE_%. (
  ECHO.firewall status already %_OPMODE_%
  EXIT /B
)

netsh firewall set opmode mode = %_OPMODE_% >nul

CALL :GET_CURRENT_STATUS

IF /I .%CURRENT_OPMODE%.==.%_OPMODE_%. (
  ECHO.firewall %_OPMODE_%D.
) ELSE (
  ECHO.SETFW failed.
)

EXIT /B


:GET_CURRENT_STATUS

SET CURRENT_PROFILE=
SET CURRENT_OPMODE=

FOR /F "tokens=1,2* delims==" %%I IN ('netsh firewall show stat') DO (
  SET _KEY_=%%I
  SET _KEY_=!_KEY_: =!
  IF "!_KEY_!"=="プロファイル" (
    SET CURRENT_PROFILE=%%J
  )
  SET _KEY_=!_KEY_: =!
  IF "!_KEY_!"=="操作モード" (
    SET CURRENT_OPMODE=%%J
  )
)

SET CURRENT_PROFILE=%CURRENT_PROFILE: =%
SET CURRENT_OPMODE=%CURRENT_OPMODE: =%

EXIT /B

:USAGE
ECHO.SETFW [ON^|OFF^|ENABLE^|DISABLE^|STATUS]
EXIT /B
※無断転載を禁止します。


Copyright (c) 1997-2019 Rakuten, Inc. All Rights Reserved.