title: Ping function returns that all pinged IP addresses is reachable
body: <p>I am tring to ping IP addresses from 192.168.1.1 to 192.168.1.254. First I was using I InetAddress class but it was bugged and some IPs where not reachable even if they are. After that I tried this method and it worked very well for single ping IP but when I put it inside for-loop all pinged IPs where reachable... Can you guys tell me what's wrong here?</p>
  
  <p>CODE:</p>
  
  <pre><code>public class Main {
  public static void main(String[] args) {
      String ip="192.168.1.";
      try
      {
          for(int i=0;i&lt;=254;i++){
          String ip2=ip+i;
          boolean reachable = (java.lang.Runtime.getRuntime().exec("ping -n 1 "+ip2).waitFor()==0);
          if(reachable){
              System.out.println("IP is reachable:: "+ip2);
          }
          else{
              System.out.println("IP is not reachable: "+ip2);
          }
          }
      }catch(Exception e)
      {
          e.printStackTrace();
      }
  
  }
  
  }
  </code></pre>
  
  <p>EDIT 1:</p>
  
  <p>I used built in Java function to preform pinging but it's not working (again)</p>
  
  <p>here is code that I used</p>
  
  <pre><code>import java.io.IOException;
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  public class Test {
  
  public static void main(String[] args) throws UnknownHostException, IOException {
      String ip = "192.168.1.243";
      InetAddress inet = InetAddress.getByName(ip);
      System.out.println("Sending Ping Request to " + ip);
      if (inet.isReachable(5000)){
          System.out.println(ip+" is reachable");
      }
      else{
          System.out.println(ip+" is not reachable");
      }
  
  }
  }
  </code></pre>
  
  <p>OUTPUT IS:</p>
  
  <pre><code>Sending Ping Request to 192.168.1.243
  192.168.1.243 is not reachable
  </code></pre>
  
  <p>Also here is ping result when I do pinging from Windows 7 built in Ping function (cmd)</p>
  
  <p><img src="https://i.stack.imgur.com/gGxyA.png" alt="enter image description here"></p>