title: Get all IP addresses from a given IP address and subnet mask
body: <p>In Java, I need to get list of all IP Addresses contained by a given IP network.</p>
  
  <p>For e.g. let the netowork be: 192.168.5.0/24 then the output will be (192.168.5.0 ... 192.168.5.255).</p>
  
  <p>I could think of the following way but it looks dirty, <strong>is there any elegant way?</strong> There is no function for the same in <code>InetAddress</code> class.</p>
  
  <ol>
  <li><p>Get Network Ip from the input Ip and subnet mask.</p>
  
  <pre><code>mask = (long)(0xffffffff) &lt;&lt; (32-subnetMask);
  Long netIp = getLongfromIp(Inputip)&amp; mask;
  </code></pre></li>
  </ol>
  
  <p>The function 'getLongfromIp' contains code from - <a href="https://stackoverflow.com/questions/12057853/how-to-convert-string-ip-numbers-to-integer-in-java">How to convert string (IP numbers) to Integer in Java</a></p>
  
  <ol start="2">
  <li><p>get the number of hosts by Subnet Mask </p>
  
  <p><code>maxRange = (long)0x1&lt;&lt;(32-subnetMask);</code></p></li>
  <li><p>Get address of all hopes by adding i <code>for i in (0 .. maxRange)</code> in the netIp</p></li>
  <li><p>Convert the ip from above step to octet string.</p></li>
  </ol>
  
  <p>Ps: I am sure the the IP Addresses will be in IPV4 only.</p>