echo off set aa=192.168.1 set outputfilename=result_%random%.txt for /l %%i in (1,1,254) do ( echo ping %aa%.%%i ping -n 1 %aa%.%%i |findstr "TTL" >nul&&echo %aa%.%%i >>c:\%outputfilename%||echo can not be reached ) echo "--------------" echo Ping %aa% done!