1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[IPアドレス変更]、[FW無効化/有効化] を簡略化するバッチファイル

Last updated at Posted at 2021-04-27

環境

Windows10

作成動機

インフラエンジニアは、NW機器にPC直結する際にFWを無効化したり、IPアドレスを変更することが多々ある。
頻度の高さの割に、その手順が手間なので作成した。

これでFWの無効化/有効化はかなり楽になる!

バッチファイルの設定方法

  1. 以下のバッチファイルの中身をコピーする。
  2. メモ帳などのテキストエディタにペーストする。
  3. 拡張子を.batにして保存する。保存場所はCドライブ直下とか適当に。
  4. 保存したbatファイルのショートカットをデスクトップに作成する。
  5. ショートカットを右クリックしてプロパティ > ショートカットタブ > 詳細設定 > 管理者として実行にチェックを入れる。

バッチファイルの使用方法

  1. バッチファイルの設定方法で作成したショートカットをダブルクリックする。
  2. 「このアプリがデバイスに変更を加えることを許可しますか?」で「はい」を選択する。
  3. コマンドプロンプトで以下の表示が出たら使用したい番号を入力する。
***********************
1. FWを無効化
2. FWを有効化
3. IPアドレスをDHCPで自動取得
4. IPアドレス/ゲートウェイを設定
5. 終了
***********************
1~5を選択してください:

バッチファイルの中身

Change_IPadd.bat
@echo off
setlocal enabledelayedexpansion
:START
echo;
echo ***********************
echo 1. FWを無効化
echo 2. FWを有効化
echo 3. IPアドレスをDHCPで自動取得
echo 4. IPアドレス/ゲートウェイを設定
echo 5. 終了
echo ***********************
set /p num=1~5を選択してください: 
 
if %num%==1 (
  netsh advfirewall set allprofiles state off
) else if %num%==2 (
  netsh advfirewall set allprofiles state on
) else if %num%==3 (
rem  netsh interface set interface イーサネット disable
rem  netsh interface set interface イーサネット enable
  netsh interface ipv4 set add name="イーサネット" source=dhcp
) else if %num%==4 (
  set /p add=IPアドレス[xxx.xxx.xxx.xxx]: 
  set /p msk=サブネットマスク[xxx.xxx.xxx.xxx]: 
  set /p gw=ゲートウェイ[xxx.xxx.xxx.xxx]: 
  netsh interface ipv4 set add name="イーサネット" source=static addr=!add! mask=!msk! gateway=!gw!
) else if %num%==5 (
  exit
) else (
  echo 1~5のどれかを選択してください
)
goto START
cmd /k
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?