I have a small script that I got from the net. This script basically reads the information (ip addresses) from a file and pings them and then inserts the results in a text file. This script does exactly what I need but the issue is that instead of ping I need “pathping” which I can change in the script. The issue is that during pathping if there is a delay the script sits for like 3 minutes or maybe 5 minute depending on the response before moving to the next IP address.
All I want is some kind of time out basically maybe like 20 sec and move to the next record regardless of what the response is. Can someone please modify the script below so that the pathping command waits for like 30 sec and then move to the next row of information (independent of what the response is). Any tips or direction would be appreciated…Thanks.
I have checked the timeout -w or -p option does not work.
@echo off
cls
echo PathPing test in progress...
for /F %%i in (iplist.txt) do pathping %%i >> result.txt
echo .
echo .
echo Result is ready.
Thank you very much.
I know this is an old post but I hope I can help others in the future. The script bellow will take each address from the iplist.txt
file and will pathping
each address for only 20 seconds. Each result will then be outputted to the result.txt
file.
Now due to how the pathping
command works, the only way to "stop" it is by terminating the CMD window it's self. Since you cannot have two lines running at a time due to how batch code is (Unlike C++ for example) we can summon two new windows using the start "" cmd /C ""
command.
For each address we summon one pathping
window and one taskkill
window. The taskill window will use the Task PID #
of the pathping window and wait 20 seconds before terminating it.
Mean while, the core batch file will wait 40 seconds for all the files to wright and close. It will then combine all the data into the result.txt
file.
@ECHO OFF
@SETLOCAL enableextensions enabledelayedexpansion
@TITLE PathPing from textfile, cancel request for each x after 20s.
@GOTO :Start
:Start
echo WARN: Starting PathPing Script...
echo WARN: This may take some time...
goto :PathPing
:PathPing
:: Large number is for token gathering
set /a number=123456789
for /f "delims== tokens=1,2" %%G in (iplist.txt) do (
:: Start The pathping's for each %%G
start "!number!" cmd /C "pathping "%%G" >> "!number!.outputfile""
:: Start Kill Window (Let process live for 20 seconds)
FOR /F "tokens=2" %%# in ('tasklist /v ^| find "!number!" ^| find "Console"') do set PID=%%#
start "" cmd /C "(PING localhost -n 20 >nul) & (taskkill /pid !PID! /t /f & goto :eof)"
set /a number+=1
)
:: End of FOR statement. Now copy .outputfile to one file.
:: Wait 60 Seconds for the FOR statement to finish copy there files.
PING localhost -n 30 >nul
:: DEL is optional, remove it if you don't with to over-wright text file.
If exist "%~dp0\result.txt" (goto :Del) ELSE (goto :Skip)
:Del
Del /Q "%~dp0\result.txt"
Goto :Skip
:Skip
For %%A In (*.outputfile) DO (for /f "delims== tokens=1,2" %%G in (%%A) do echo %%G >> result.txt)
:: Clean up all .outputfile files.
For %%A In (*.outputfile) DO (DEL /Q "%~dp0\%%A")
Goto :Finish
:Finish
cls
echo WARN: Result is ready.
echo(
pause
goto :eof