2020年9月25日金曜日

[bat]サンプル1

[bat]サンプル1

IPアドレス・FireWallの切り替えを行うバッチスクリプト

@echo off

rem +--------------------------------------------+
rem | 設定                                       |
rem +--------------------------------------------+
set Address=192.168.100.111
set GateWay=192.168.100.1

rem +--------------------------------------------+
rem | 実行                                       |
rem +--------------------------------------------+
rem  call :Disable_FW
rem  call :Set_Address

     call :Enable_FW
     call :Set_DHCP

timeout 2
ipconfig
pause
exit

rem +--------------------------------------------+
rem | 実行内容                                   |
rem +--------------------------------------------+
:Enable_FW
  netsh advfirewall set allprofiles    state on
  exit /b

:Disable_FW
  netsh advfirewall set privateprofile state off
  netsh advfirewall set publicprofile  state off
  exit /b

:Set_DHCP
  call :get_Ether
  netsh interface ipv4 set address name=%Local_Network% source=dhcp
  exit /b

:Set_Address
  call :get_Ether
  netsh interface ipv4 set address name=%Local_Network% source=static address=%Address% mask=255.255.255.0 gateway=%GateWay%
  exit /b

:get_Ether
  for /f "tokens=1,2,*" %%A in ('ipconfig /all ^| find "イーサネット アダプター イーサネット"') do (
    set Network_Name=%%C
  )
  set Local_Network=%Network_Name:~0,-1%
  exit /b

0 件のコメント: