Batch just crashes after too many ping attempts

Viewed 40

I try to find out of a list of similar addresses, if I can ping some of those. But after about 304 ping attemps/fails, the script just crashes.

@echo off

echo Start
set /A PORT=0
call:start
echo Finished
pause

:start
set /A PORT=%PORT%+1
set ADRESS=http://Adress.servehttp.com:%PORT%
ping /n 1 %ADRESS%
if %ERRORLEVEL% EQU 0 (echo %ADRESS% >> results.log)
if %PORT% LEQ 65535 (call:start) ELSE pause
1 Answers

Your start function is recursive and you have reached the stack limit allowed for a batch script which is usually very low.

You can solve this problem by using a loop instead.

Related