title: How can I get all IP addresses of a subnet which run on a specific port
body: <p>I want to find all systems that are on the same local network i.e. that have the same subnet mask.</p>
  <p>I think I must work with <code>InetAddress</code> Class in Java but I don't know what should I do.
  My algorithm is:</p>
  <blockquote>
  <ol>
  <li><p>Find all available system in a local network</p>
  </li>
  <li><p>Check if they run on a my requested port</p>
  </li>
  <li><p>Keep in mind the IP of system which runs on this port</p>
  </li>
  </ol>
  </blockquote>
  <pre><code>InetAddress localHost = Inet4Address.getLocalHost(); 
  NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost);
  System.out.println(networkInterface);
  networkInterface.getByInetAddress(localHost);
      
  for (){
      networkInterface.getByInetAddress(localHost) 
  }
  </code></pre>
  <p>I think that the <code>networkInterface.getByInetAddress(localHost)</code> can give me all available IP addresses in a subnet, but I don't how I can do this for all available systems, and what is the condition for the <code>for</code> clause.</p>