Skip to content

Instantly share code, notes, and snippets.

@theCrius
Created December 21, 2017 10:54
Show Gist options
  • Save theCrius/2e04a01fbfb6bff0687eeb6f186b1cef to your computer and use it in GitHub Desktop.
Save theCrius/2e04a01fbfb6bff0687eeb6f186b1cef to your computer and use it in GitHub Desktop.
Windows .bat file to run and log to file a ping to any host while adding timestamp
@echo off
set /p host=host Address:
set logfile=Log_%host%.log
echo Target Host = %host% >%logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>%logfile%
echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
timeout 1 >NUL
GOTO Ping)
@theCrius
Copy link
Author

I kept having to search on stack-overflow for the right script and got tired of wasting 10 minutes every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment