title: Batch - Script ping multiple ip
body: <p>I want to make a script to ping many IP addresses. But I don't want to use errorlevel.</p>
  
  <p>I want to ping each IP address 5 times, and display the result:</p>
  
  <ul>
  <li>If 5 packets lost I want to display an echo %ip - DOWN </li>
  <li>If 3 packets lost I want to display an echo %ip - 3 lost</li>
  <li>etc...</li>
  </ul>
  
  <p>So I want get back "lost packets" in a variable from this line : </p>
  
  <p>"packets: sent = 4, received = 4, <strong>lost = 0</strong> (0% loss) </p>
  
  <p>This is my code but this doesn't work.</p>
  
  <pre><code>echo off 
  
  set perte=0 
  set servers=servers.txt 
  
  for /f %%i in (%servers%) do call :testping %%i 
  goto:eof
  
  :testping 
  FOR /f "tokens=3 delims==" %%a IN (' ping -n 5 %1 ^|find "lost"') 
  DO (set perte=%%b) 
  
  if %perte%==1 echo %1 lost 1 ping
  if %perte%==2 echo %1 lost 2 ping
  if %perte%==3 echo %1 lost 3 ping
  if %perte%==4 echo %1 lost 4 ping
  if %perte%==5 echo %1 DOWN
  if %perte%==0 echo %1 UP
  goto:eof
  </code></pre>