Advertisement
Guest User

LogPing v3

a guest
Jun 27th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. rem This batch file pings an IP and logs whether it was successful or not
  3. rem If ping fails, tracert will be run to help diagnose
  4.  
  5. rem These are the values used throughout the batch file. Change them here if you like.
  6. set myIP=4.2.2.2
  7. set myFile=.\Internet.txt
  8. set myTimeout=5
  9.  
  10. :START
  11. @echo off
  12. ping -n 4 %myIP% -w 1000 | findstr /r /c:"[0-9] *ms" >nul
  13.  
  14. if %errorlevel% == 1 (
  15.   echo %DATE% %TIME% Internet offline
  16.   echo %DATE% %TIME% Internet offline >> %myFile%
  17.   echo Beginning Traceroute!
  18.   echo Beginning Traceroute >> %myFile%
  19.   tracert %myIP% >> %myFile%
  20. ) else (
  21.   echo %DATE% %TIME% Internet online
  22.   echo %DATE% %TIME% Internet online >> %myFile%
  23. )
  24.  
  25. rem You can change this timeout but by default it waits 5 seconds between pings
  26. Timeout /t %myTimeout%
  27. @set errorlevel = 0
  28.  
  29. GOTO START
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement