From 6539ccf24280535303a009b6d7be96c0cc7d1e2d Mon Sep 17 00:00:00 2001 From: LizenzFass78851 <82592556+LizenzFass78851@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:51:32 +0100 Subject: [PATCH] Add `Ping Logger` Script --- Ping Logger/README.md | 3 +++ Ping Logger/ping_logger.bat | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Ping Logger/README.md create mode 100644 Ping Logger/ping_logger.bat diff --git a/Ping Logger/README.md b/Ping Logger/README.md new file mode 100644 index 0000000..542b3df --- /dev/null +++ b/Ping Logger/README.md @@ -0,0 +1,3 @@ +## Ping Logger +- a script for logging ping results in a txt file in order to be able to determine ping times for a ping target over a longer period of time. +- everything else that can be set (e.g. ping target, wait time, end time for the script run, etc.) can be set as variables in the script. \ No newline at end of file diff --git a/Ping Logger/ping_logger.bat b/Ping Logger/ping_logger.bat new file mode 100644 index 0000000..5c5999c --- /dev/null +++ b/Ping Logger/ping_logger.bat @@ -0,0 +1,45 @@ +@echo off +setlocal enabledelayedexpansion + +REM destination address for the ping +set target=192.168.178.1 + +REM log file +set logfile=%target%-ping_log.txt + +REM Waiting time in seconds +set waittime=1 + +REM End time (in format HH:MM), leave blank for infinite running +set endtime= + +REM Current time +for /f "tokens=1-2 delims=:" %%a in ("%time%") do set currenttime=%%a:%%b + +REM Set the beginning of the log file +echo -------------------------------------------------- +echo !date! !time! - Starte Ping_Logger für Target: %target% +echo -------------------------------------------------- +echo -------------------------------------------------- >> %logfile% +echo !date! !time! - Starte Ping_Logger für Target: %target% >> %logfile% +echo -------------------------------------------------- >> %logfile% + +REM ping loop +:pingloop +for /f "tokens=1-2 delims=:" %%a in ("%time%") do set currenttime=%%a:%%b +if defined endtime if "!currenttime!" geq "%endtime%" goto end + +REM Ping command and logging the result +for /f "tokens=4-5 delims= " %%a in ('ping -n 1 %target% ^| find "Zeit="') do ( + set pingtime=%%b + echo !date! !time! - %target% ist erreichbar - !pingtime! + echo !date! !time! - %target% ist erreichbar - !pingtime! >> %logfile% +) + +REM waiting time +timeout /t %waittime% >nul + +goto pingloop + +:end +echo Ping script terminated.