Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal enabledelayedexpansion
- chcp 65001 >nul
- title TruePing
- :: Check if cecho exists
- set "use_color="
- where cecho >nul 2>&1 && set "use_color=1"
- :: Define symbols with colors if cecho exists, or without colors if not
- if defined use_color (
- set "green_symbol={0A}√{#}"
- set "red_symbol={0C}Χ{#}"
- ) else (
- set "green_symbol=√"
- set "red_symbol=Χ"
- )
- :: #########################################################
- :: ### CONFIGURATION - EDIT THESE VALUES AS NEEDED ###
- :: #########################################################
- :: Set the switch interval (seconds)
- set "interval_seconds=900"
- :: Set target IPs (space-separated)
- set "ip_list=1.1.1.1 1.0.0.1 8.8.4.4 8.8.8.8"
- :: #########################################################
- :: ### HOW TO USE ###
- :: #########################################################
- :: 1. Change "interval_seconds" to any value (e.g., 60 for 1 min, 3600 for 1 hour)
- :: 2. Add/remove IPs in "ip_list" (keep them space-separated)
- :: 3. Run the script (double-click or in CMD)
- :: 4. Press Ctrl+C to stop
- :: #########################################################
- :init
- :: Split IPs into an array for easy rotation
- set ip_count=0
- for %%a in (%ip_list%) do (
- set /a ip_count+=1
- set "ip_!ip_count!=%%a"
- )
- set "current_ip=1"
- :loop
- :: Get current IP from our array
- set "target_ip=!ip_%current_ip%!"
- :: Ping loop for the configured interval
- set "count=0"
- :ping_loop
- :: Get timestamp (HH:MM:SS) for logging
- for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value 2^>nul') do set datetime=%%a
- set timestamp=!datetime:~8,2!:!datetime:~10,2!:!datetime:~12,2!
- :: Ping the target IP and parse response time
- for /f "tokens=7 delims== " %%m in ('ping -n 1 !target_ip! ^| find "time="') do (
- if defined use_color (
- cecho [!timestamp!] !green_symbol! !target_ip! ^| %%m{\n}
- ) else (
- echo [!timestamp!] !green_symbol! !target_ip! ^| %%m
- )
- goto ping_wait
- )
- :: If no 'time=', assume failure
- if defined use_color (
- cecho [!timestamp!] !red_symbol! !target_ip! ^| {0C}NO RESPONSE{#}{\n}
- ) else (
- echo [!timestamp!] !red_symbol! !target_ip! ^| NO RESPONSE
- )
- :ping_wait
- :: Wait 1 second before next ping attempt
- timeout /t 1 /nobreak >nul
- :: Check if we've reached the configured interval
- set /a count+=1
- if !count! lss !interval_seconds! goto ping_loop
- :: Switch to next IP in rotation
- set /a current_ip+=1
- if !current_ip! gtr !ip_count! set current_ip=1
- :: Continue with the next IP
- goto loop
Advertisement
Add Comment
Please, Sign In to add comment