1.

Solve : Need help modifying DOS script for continuous ping?

Answer»

Hello,

I have the following script that almost works exactly the way I need it to. Basically I want to continuously ping an IP address and timestamp it to the screen. The problem with the script below is that is only pings 1 time. I want a continously ping say every 30 seconds or so.

Any help would be greatly appreciated.

Thx!

@ECHO off
setlocal

set IP=192.168.1.1

echo Pinging %IP%...

for /l %%a in (1,1,4) do call :pingIt %IP%

endlocal
echo [Done]

:pingIt
for /f "tokens=*" %%a in ('ping -n 1 %1') do @echo %time% %%a |find "Reply from "
goto :eofYour code could be SIMPLIFIED but this should work for you:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set IP=192.168.1.1
:loop
echo Pinging %IP%...
for /l %%a in (1,1,4) do call :pingIt %IP%
echo [Done]
timeout 30 >nul
goto :loop

:pingIt
for /f "delims=" %%a in ('ping -n 1 %1') do @echo !date! @ !time! - %%a |find "Reply from "
goto :eof
Foxidrive, awesome!!! Thanks so much, this works perfectly! I spent hours Google searching yesterday and couldn't find what I needed.

Thanks againI had a follow up to this question..... SINCE DOS does not support logging the output to a file, is there anyway to log this output and save to a file?

ThanksMy two cents.
Constant pinging is not a good practice. If you need to analyze a network connection, there are others software and HARDWARE tools.
Just saving.
Agreed 100%, however I am trying to test battery CAPACITY, i.e. send a constant ping to a device that is running on batteries to determine how many hours it will last.

ThxQuote from: gil_happy on October 07, 2013, 05:26:57 PM

I had a follow up to this question..... Since DOS does not support logging the output to a file,

You are mistaken.

Quote from:
is there anyway to log this output and save to a file?

Code: [Select]"batchfile.bat" >file.log
and

Code: [Select]>>file.log ping localhost Foxidrive, once again, awesome!

ThxJust building off what Foxidrive said,
">" Overrides the file
">>" edits the file (adding output to the end)


Discussion

No Comment Found