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 1 year has passed since last update.

Wiresharkで定時に一定時間パケットキャプチャー

Last updated at Posted at 2024-02-06

やりたいこと

例えば…

  1. 毎日AM09:00になったらWiresharkを自動起動。
  2. その後、15分間パケットキャプチャ―したらWireshark終了。

処理概要

『引数を渡してWiresharkを起動させて、一定時間後にWiresharkを終了させる』というbatを用意。
上記のbatをタスクスケジューラーで起動。

bat

rem Wiresharkで900秒=15分パケットキャプチャー。
start "" "C:\Program Files\Wireshark\Wireshark.exe" -i 4 -a duration:900 -w %~dp0%date:~0,4%%date:~5,2%%date:~8,2%_%COMPUTERNAME%.pcapng -k


rem Wiresharkの画面が残らないようにキャプチャー終了を見計らってタスク終了。
rem Wireshark起動からパケットキャプチャー開始までのラグを考慮してキャプチャー時間より少しプラスして待つ。
timeout /t 1200 /nobreak >nul
taskkill /im Wireshark.exe /f

Wireshark起動時の引数

-i 4

どのインターフェースのパケットをキャプチャーするか を指定しています。
4 はインターフェース番号なので、適宜読み替えて下さい。

インターフェース番号を調べるには、コマンドプロンプトでまず下記。

コマンドプロンプトをUTF-8に切替
CHCP 65001

文字コードを切り替えたら下記。

Wiresharkのインターフェース番号確認
"C:\Program Files\Wireshark\Wireshark.exe" -D

-a duration:900

900秒パケットキャプチャ―したら パケットキャプチャ―を終了 します。
あくまでキャプチャーが終了するだけで、Wiresharkの画面は残ります。

-w %~dp0%date:~0,4%%date:~5,2%%date:~8,2%_%COMPUTERNAME%.pcapng

キャプチャー結果をbatファイルと同じフォルダーに保存。
ファイル名は『yyyyMMdd_PC名.pcapng』という設定です。

-k

Wireshark起動と同時にキャプチャー開始。

タスクスケジューラー

『スリープや定時再起動によって実行されなかった』といったことが無いように注意。

参考サイトさん

バージョン

Microsoft Windows [Version 10.0.19045.3996]
Wireshark 4.2.2

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?