0
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.

ping できるノードを見つける & サーバを一括監視する

Last updated at Posted at 2020-11-29

ping が返ってくるノード一覧を表示するバッチファイル。 および、
サーバ等が online かどうかを調べるバッチファイル。
こういうツールは たくさんあるけれど、DOS バッチファイルなのでツールを持ち込めない環境などでも使える。

Raspberry Pi を見つけるための方法を、ぐぐったけど案外 見つからなかったので作ってみた。
環境に合わせて適宜変更を。

文字化けするときは UTF-8 じゃなく Shift-JIS (ANSI) で保存。
(実行環境: Windows10 , Windows7 , ...)


1行で ping が返ってくるノードを見つける。

コマンドプロンプトにコピペして実行。

for /l %i in (1,1,254) do @ping -w 1 -n 1 192.168.11.%i | find "TTL" 

ping が返ってくるノードを見つけるバッチファイル。

SearchIP.bat

@echo off
cls

set network=192.168.11.

echo.
for /l %%i in (1,1,254) do for /F "usebackq tokens=*" %%j in (`ping -w 1 -n 1 %network%%%i`) do echo "%%j" | find "TTL"
echo.
pause
goto :eof

実行結果

"192.168.11.1 からの応答: バイト数 =32 時間 =1ms TTL=64"
"192.168.11.2 からの応答: バイト数 =32 時間 <1ms TTL=128"
"192.168.11.9 からの応答: バイト数 =32 時間 =30ms TTL=64"
続行するには何かキーを押してください . . .

ping が返ってくるノードを見つけ MAC アドレスも表示するバッチファイル。

SearchIPandMAC.bat

@echo off
cls

set network=192.168.11.

echo.
setlocal enabledelayedexpansion
for /l %%i in (1,1,254) do (
  set ip=""
  for /F "usebackq tokens=*" %%j in (`ping -w 1 -n 1 %network%%%i`) do (
    echo "%%j" | find "TTL" > NUL: && set ip=yes
  )
  if not "!ip!" == "" (
    arp -a %network%%%i | find "%network%%%i"
  )
)
echo.
pause
goto :eof

実行結果

  192.168.11.1          xx-xx-xx-xx-xx-xx     動的
  192.168.11.9          xx-xx-xx-xx-xx-xx     動的
続行するには何かキーを押してください . . .

監視対象のサーバから ping が返ってくるかを確認するバッチファイル。

監視対象のサーバは ping_server.txt に記述する。
1行に1サーバを書き、レコードの先頭は IP アドレス。

ping_server.bat

@echo off
cls
echo.

set list=%~dpn0.txt

setlocal enabledelayedexpansion
for /f "tokens=1" %%i in (%list%) do for /F "usebackq tokens=*" %%j in (`ping -w 1 -n 1 %network%%%i`) do (
  echo "%%j" | find "TTL"
  echo "%%j" | > NUL: find "タイムアウト" && echo "%%i  is not reachable at !date! !time!"
)
echo.
pause
goto :eof

サーバ一覧ファイル 例

ping_server.txt
192.168.11.1	server1
192.168.11.2	server2
192.168.11.3	server3
192.168.11.16	server16
192.168.11.17	server17
192.168.11.18	server18

実行結果

C:\> ping_server.bat

"192.168.11.1 からの応答: バイト数 =32 時間 <1ms TTL=64"
"192.168.11.2  is not reachable at 2020/12/03 20:52:16.78"
"192.168.11.3  is not reachable at 2020/12/03 20:52:17.28"
"192.168.11.16 からの応答: バイト数 =32 時間 =22ms TTL=64"
"192.168.11.17 からの応答: バイト数 =32 時間 =32ms TTL=128"
"192.168.11.18  is not reachable at 2020/12/03 20:52:19.77"
続行するには何かキーを押してください . . .

(無料 アプリ フリーウェア)

0
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
0
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?