Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: |---------------------------------------------------------------------------------------------------|
- :: | SPT3 - Slow Ping Test (Version 3) Created By: Devanov |
- :: |---------------------------------------------------------------------------------------------------|
- :: |
- :: | 1. What is the script meant for?
- :: |
- :: | To let run for extended periods (>30 days) on a windows device,
- :: | to monitor connections to pre-defined targets via ICMP-Ping requests
- :: | with the focus on logging occurances in a continous log-file.
- :: |
- :: | 2. Why is the script CMD-based?
- :: |
- :: | The creator of this script is no programmer.
- :: | Furthermore, the script was meant to run with minimal requirements within windows OS.
- :: | It only relied on CMD, with later additions incorporating basic Powershell elements.
- :: | The focus of the script remained the logging and therefore the output, CMD "ping" generated.
- :: |
- :: | 3. Why am I getting an Access-Error on startup?
- :: |
- :: | Before the script starts into the loop, it issues a request to resync the NTP (time) server.
- :: | This step is to ensure that the timestamps within the log-file are correct for the timezone.
- :: | The Time-Resync however requires administrative permissions.
- :: | It is suggested to execute as Admin, but not required.
- :: | The output of the issued command (wether successful or not) will be logged too.
- :: | Note: Before issuing this command, the script tries to start the w32time service required for NTP (silent).
- :: |
- :: | 4. What happens when the script is aborted/restarted? What if it is moved or the log deleted?
- :: |
- :: | As the script only adds to the (existing) SlowPingTest.log file, there will be no data loss upon exiting.
- :: | But the script does not restart on its own if cancelled.
- :: | The script will always search for a log-file in the directory it is located in;
- :: | if not file is present, it will generate one. If one is present, it just adds content to it.
- :: |
- :: | 5. I want to change the ping-targets or the display name in the log.
- :: |
- :: | Right click the .bat file and open in Editor (or Notepad++).
- :: | change values within the "set" commands. EXAMPLE:
- :: | set "var1=YourFirstTargetName" (Keep character-count same for var1,2,3 for log-readability)
- :: | set "srv1=YourFirstTargetAddress" (Can be IP or DNS)
- :: |
- :: | 6. I want to suppress the output in CLI (for RAM savings or silent executions).
- :: |
- :: | Remove the following part of each "single-long-line" argument:
- :: | & powershell -command "Get-Content %cd%\SlowPingTest.log | Select-Object -Last 1"
- :: | ------------
- :: | Change this:
- :: | findstr "%timeout% %error%" "%SPTTEMP%" >nul && (set /p "= %date% / %time% / %var1% / " <nul >> "%cd%\SlowPingTest.log" & findstr "%timeout% %error%" "%SPTTEMP%" >> "%cd%\SlowPingTest.log" & powershell -command "Get-Content %cd%\SlowPingTest.log | Select-Object -Last 1")
- :: | To this (Please keep in mind to adjust %var1% if copy-pasting):
- :: | findstr "%timeout% %error%" "%SPTTEMP%" >nul && (set /p "= %date% / %time% / %var1% / " <nul >> "%cd%\SlowPingTest.log" & findstr "%timeout% %error%" "%SPTTEMP%" >> "%cd%\SlowPingTest.log")
- :: |
- :: |---------------------------------------------------------------------------------------------------|
- :: | Date Of Update: 14.04.2024 Original: 02.02.2023 |
- :: |---------------------------------------------------------------------------------------------------|
- @echo off
- cd "%~dp0"
- set "var1=Cloudflare"
- set "srv1=1.1.1.1"
- set "var2=Google-DNS"
- set "srv2=8.8.8.8"
- set "var3=Google.com"
- set "srv3=google.com"
- set cooldown=0
- :: Time delay between ping-request from srv1>2 and srv2>3 (default: 0) // Warning: Increasing this can cause issues if time between cycles isn't increased as well
- :: Time delay between issued "cylces" of 3 requests is manually set at the last powershell-line of the script (logic: 60/15=4 -- 0,15,30,45) // Default: 15 (Alternative: 30,60)
- set "success=TTL"
- set "timeout=Anforderung Zielhost Zielnetz"
- set "error=Fehler"
- set "ntp=erfolgreich Fehler"
- :: Please adjust variables based on OS language (Default: German)
- set "SPTTEMP=%cd%\SPT.temp"
- echo ----------------
- echo SlowPingTest.bat
- echo ----------------
- echo =====================================================================================>> %cd%\SlowPingTest.log
- sc start w32time
- echo | set /p=%date% / %time% / RESYNC-NTP />> %cd%\SlowPingTest.log & @w32tm /resync | findstr "%ntp%" >> %cd%\SlowPingTest.log
- powershell -command "Get-Content %cd%\SlowPingTest.log | Select-Object -Last 1"
- :loop
- setlocal
- @ping %srv1% -l 0 -n 1 > "%SPTTEMP%"
- findstr "%timeout% %error%" "%SPTTEMP%" >nul && (set /p "= %date% / %time% / %var1% / " <nul >> "%cd%\SlowPingTest.log" & findstr "%timeout% %error%" "%SPTTEMP%" >> "%cd%\SlowPingTest.log" & powershell -command "Get-Content %cd%\SlowPingTest.log | Select-Object -Last 1")
- endlocal
- timeout %cooldown% /nobreak>nul
- setlocal
- @ping %srv2% -l 0 -n 1 > "%SPTTEMP%"
- findstr "%timeout% %error%" "%SPTTEMP%" >nul && (set /p "= %date% / %time% / %var2% / " <nul >> "%cd%\SlowPingTest.log" & findstr "%timeout% %error%" "%SPTTEMP%" >> "%cd%\SlowPingTest.log" & powershell -command "Get-Content %cd%\SlowPingTest.log | Select-Object -Last 1")
- endlocal
- timeout %cooldown% /nobreak>nul
- setlocal
- @ping %srv3% -l 0 -n 1 > "%SPTTEMP%"
- findstr "%timeout% %error%" "%SPTTEMP%" >nul && (set /p "= %date% / %time% / %var3% / " <nul >> "%cd%\SlowPingTest.log" & findstr "%timeout% %error%" "%SPTTEMP%" >> "%cd%\SlowPingTest.log" & powershell -command "Get-Content %cd%\SlowPingTest.log | Select-Object -Last 1")
- endlocal
- powershell -Command "$waitSeconds = 15 - (Get-Date).Second %% 15; Start-Sleep -Seconds $waitSeconds"
- goto loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement