Ping to File

From TheAlmightyGuru
Revision as of 11:10, 31 August 2017 by TheAlmightyGuru (talk | contribs) (Created page with "'''''Ping to File''''' is a Windows command line batch script that will execute a ping command and log the results to a file rather than to the screen. Copy and past the foll...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Ping to File is a Windows command line batch script that will execute a ping command and log the results to a file rather than to the screen.

Copy and past the following code into a text file and give it a .bat extension, then run it from the command line. You will be prompted for the target address, and the log will be saved in a file named "Log_[target address].log" in the same folder.

Source

@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)