title: Batch Script to find out whether a host is up or down
body: <p>I need to scan several systems in the network within IP range 172.18.x.x to 172.25.x.x and check whether each of them is active or not, and then dump the result in a file.
  Following is the script:</p>
  
  <pre><code>@echo off
  for /L %%x in (18,1,25) do (
      for /L %%y in (1,1,254) do (
          for /L %%z in (1,1,254) do (
  
      ping -n 1 172.%x.%y.%z | find "Reply" &gt; NUL
      IF NOT ERRORLEVEL 1 (set state=UP) ELSE (set state=DOWN)
  
      echo 172.%%x.%%y.%%z is %state% &gt;&gt; state.txt
  )))
  </code></pre>
  
  <p>But, the result concludes that every system is 'UP' even though some IP addresses are unused.</p>
  
  <p>Any problem with the script?</p>