[ホーム] - [Windows 11 FAQ 一覧] - [インターネットスピードの測定を自動バッチで一定間隔で行うサンプルコード | ]



作成日:2023/10/04
更新日:2023/10/04
対象:Windows 11

インターネットスピードの測定を自動バッチで一定間隔で行うサンプルコード |




【目次】

インターネット接続のスピードをテストする


高速インターネットを利用していても遅く感じることがたまにあります。google speed テストを実施しても問題なし。
そのような場合、自動で一定期間、性能を計測できたらよいと思うでしょう。連続で測定すれば遅い瞬間が分かるかもしれないからです。

インターネット接続テストで有名なのは ookla (オークラと読むらしい) のスピードテストです。
Web版とCLI版があります。

・Web版(ブラウザからすぐにテスト)
https://www.speedtest.net/ja

・CLI(コマンドライン版、コマンドプロンプトから実行)
https://www.speedtest.net/ja/apps/cli

macOS , Ubuntu/Debian , Fedora/Centos/Redhat , FreeBSD , Windows 版 があるようです。

サンプルコード


サンプルコードを紹介します。その前にライセンスに同意する必要があります。
まずは、そのPCで一度だけ speedtest.exe を実行してください。次のとおりライセンス同意が表示されるので、同意するには"yes"を選択します。


Do you accept the license? [type YES to accept]: yes
License acceptance recorded. Continuing.




次はWindowsのサンプルコードです。ダウンロードしたspeedtest.exeを c:\speedtest に保存して、同じフォルダに sample.bat を作成して実行してください。
30分ごとに実行されます。

sample.bat

time /T >> c:\speedtest\kekka.txt
date /T >> c:\speedtest\kekka.txt

:loop
C:\speedtest\speedtest.exe -f csv >> c:\speedtest\kekka.txt

timeout 1800

goto loop



-f csv オプションにより後で csv として Excel などで処理可能としています。

その他のオプションは次の通りです。バージョン1.2.0.84 のオプションです。


Usage: speedtest [<options>]
-h, --help Print usage information
-V, --version Print version number
-L, --servers List nearest servers
-s, --server-id=# Specify a server from the server list using its id
-I, --interface=ARG Attempt to bind to the specified interface when connecting to servers
-i, --ip=ARG Attempt to bind to the specified IP address when connecting to servers
-o, --host=ARG Specify a server, from the server list, using its host's fully qualified domain name
-p, --progress=yes|no Enable or disable progress bar (Note: only available for 'human-readable'
or 'json' and defaults to yes when interactive)
-P, --precision=# Number of decimals to use (0-8, default=2)
-f, --format=ARG Output format (see below for valid formats)
--progress-update-interval=# Progress update interval (100-1000 milliseconds)
-u, --unit[=ARG] Output unit for displaying speeds (Note: this is only applicable
for human-readable output format and the default unit is Mbps)
-a Shortcut for [-u auto-decimal-bits]
-A Shortcut for [-u auto-decimal-bytes]
-b Shortcut for [-u auto-binary-bits]
-B Shortcut for [-u auto-binary-bytes]
--selection-details Show server selection details
-v Logging verbosity. Specify multiple times for higher verbosity
--output-header Show output header for CSV and TSV formats

Valid output formats: human-readable (default), csv, tsv, json, jsonl, json-pretty

Machine readable formats (csv, tsv, json, jsonl, json-pretty) use bytes as the unit of measure with max precision

Valid units for [-u] flag:
Decimal prefix, bits per second: bps, kbps, Mbps, Gbps
Decimal prefix, bytes per second: B/s, kB/s, MB/s, GB/s
Binary prefix, bits per second: kibps, Mibps, Gibps
Binary prefix, bytes per second: kiB/s, MiB/s, GiB/s
Auto-scaled prefix: auto-binary-bits, auto-binary-bytes, auto-decimal-bits, auto-decimal-bytes



エラー


(1)リクエストが多い

連続してリクエストを実行すると次のエラーで失敗する場合があるようです。

"Too many requests received.To maintain・・・"

一定時間を空けてから実行する必要があると思われます。

(2)ファイル書き込み
"別のプロセスが・・・"でログファイルに書き込みできない場合、他のプロセスがログファイルを開いている可能性があります。
テキストエディタなどが開いていないことを確認します。


原因不明のエラー


次の2個の原因不明なエラーが発生しました。理由は不明です。その後実行したところ成功しました。


[error] (null). WSA Error of type 11001 with message 3K[:
[error] Configuration - Couldn't resolve host name (HostNotFoundException)
[error] Configuration - Cannot retrieve configuration document (0)
[error] ConfigurationError - Could not retrieve or read configuration (Configuration)
[error] ConfigurationError - Could not retrieve or read configuration (Configuration)
[error] Configuration - Could not retrieve or read configuration (ConfigurationError)




[error] (null). WSA Error of type 11001 with message
[error] Error: [11001] そのようなホストは不明です。









(ご注意) 本サイト内の内容を使用して発生したいかなる時間的損害、金銭的損害あるいはいかなる損害に対して、いかなる人物も一切の責任を負いません。あくまでも個人の判断で使用してください。 本ページは独自に調査をしたアンオフィシャル(非公式)な内容です。内容に誤りがある可能性や仕様変更により内容が不正確になる可能性があります。 本サイト内掲載されている情報は、著作権法により保護されています。いかなる場合でも権利者の許可なくコピー、配布することはできません。 このページはリンクフリーです。(このページへの直接リンクも可能です。)


Copyright(c) TOOLJP.COM 1999-2022

[Windows 11 FAQ 一覧に戻る]