title: Find all IP addresses in local network
body: <p>I want to find all IP addresses of devices in the local network I'm currently connected to using Java code. The useful utility <a href="http://www.advanced-ip-scanner.com/" rel="noreferrer"><code>Advanced IP Scanner</code></a> is able to find various IP addresses in my <a href="https://en.wikipedia.org/wiki/Subnetwork" rel="noreferrer">subnet</a> of <code>192.168.178/24</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/GR8p5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GR8p5.png" alt=""></a></p>
  
  <p>According to <a href="https://stackoverflow.com/a/3345981/3764804">this</a> answer, I built my code the following way:</p>
  
  <pre><code>import java.io.IOException;
  import java.net.InetAddress;
  
  public class IPScanner
  {
      public static void checkHosts(String subnet) throws IOException
      {
          int timeout = 100;
          for (int i = 1; i &lt; 255; i++)
          {
              String host = subnet + "." + i;
              if (InetAddress.getByName(host).isReachable(timeout))
              {
                  System.out.println(host + " is reachable");
              }
          }
      }
  
      public static void main(String[] arguments) throws IOException
      {
          checkHosts("192.168.178");
      }
  }
  </code></pre>
  
  <p>Unfortunately, this does not print out any results, meaning that no IP addresses are reachable. Why? There are devices in my local network like seen in the <code>Advanced IP Scanner</code> scan.</p>