Automage

TruePing

Sep 7th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. chcp 65001 >nul
  4. title TruePing
  5.  
  6. :: Check if cecho exists
  7. set "use_color="
  8. where cecho >nul 2>&1 && set "use_color=1"
  9.  
  10. :: Define symbols with colors if cecho exists, or without colors if not
  11. if defined use_color (
  12. set "green_symbol={0A}√{#}"
  13. set "red_symbol={0C}Χ{#}"
  14. ) else (
  15. set "green_symbol=√"
  16. set "red_symbol=Χ"
  17. )
  18.  
  19. :: #########################################################
  20. :: ### CONFIGURATION - EDIT THESE VALUES AS NEEDED ###
  21. :: #########################################################
  22.  
  23. :: Set the switch interval (seconds)
  24. set "interval_seconds=900"
  25.  
  26. :: Set target IPs (space-separated)
  27. set "ip_list=1.1.1.1 1.0.0.1 8.8.4.4 8.8.8.8"
  28.  
  29. :: #########################################################
  30. :: ### HOW TO USE ###
  31. :: #########################################################
  32. :: 1. Change "interval_seconds" to any value (e.g., 60 for 1 min, 3600 for 1 hour)
  33. :: 2. Add/remove IPs in "ip_list" (keep them space-separated)
  34. :: 3. Run the script (double-click or in CMD)
  35. :: 4. Press Ctrl+C to stop
  36. :: #########################################################
  37.  
  38. :init
  39. :: Split IPs into an array for easy rotation
  40. set ip_count=0
  41. for %%a in (%ip_list%) do (
  42. set /a ip_count+=1
  43. set "ip_!ip_count!=%%a"
  44. )
  45. set "current_ip=1"
  46.  
  47. :loop
  48. :: Get current IP from our array
  49. set "target_ip=!ip_%current_ip%!"
  50.  
  51. :: Ping loop for the configured interval
  52. set "count=0"
  53. :ping_loop
  54.  
  55. :: Get timestamp (HH:MM:SS) for logging
  56. for /f "tokens=2 delims==" %%a in ('wmic os get localdatetime /value 2^>nul') do set datetime=%%a
  57. set timestamp=!datetime:~8,2!:!datetime:~10,2!:!datetime:~12,2!
  58.  
  59. :: Ping the target IP and parse response time
  60. for /f "tokens=7 delims== " %%m in ('ping -n 1 !target_ip! ^| find "time="') do (
  61. if defined use_color (
  62. cecho [!timestamp!] !green_symbol! !target_ip! ^| %%m{\n}
  63. ) else (
  64. echo [!timestamp!] !green_symbol! !target_ip! ^| %%m
  65. )
  66. goto ping_wait
  67. )
  68.  
  69. :: If no 'time=', assume failure
  70. if defined use_color (
  71. cecho [!timestamp!] !red_symbol! !target_ip! ^| {0C}NO RESPONSE{#}{\n}
  72. ) else (
  73. echo [!timestamp!] !red_symbol! !target_ip! ^| NO RESPONSE
  74. )
  75.  
  76. :ping_wait
  77. :: Wait 1 second before next ping attempt
  78. timeout /t 1 /nobreak >nul
  79.  
  80. :: Check if we've reached the configured interval
  81. set /a count+=1
  82. if !count! lss !interval_seconds! goto ping_loop
  83.  
  84. :: Switch to next IP in rotation
  85. set /a current_ip+=1
  86. if !current_ip! gtr !ip_count! set current_ip=1
  87.  
  88. :: Continue with the next IP
  89. goto loop
Advertisement
Add Comment
Please, Sign In to add comment