Split an IP address into Octets, then do some math on each of the Octets
<p>I actually have this working, but its very ugly, and its keeping me awake at night trying to come up with an eloquent piece of code to accomplish it.</p>

<p>I need to take a series of strings representing IP Ranges and determine how many actual IP address that string would represent.  My approach has been to split that into 4 octets, then attempt to split each octet and do the math from there.  </p>

<p>e.g.: 1.2.3.4-6 represents 1.2.3.4, 1.2.3.5, and 1.2.3.6, thus I want to get the answer of 3 from this range.</p>

<p>To further complicate it, the string I'm starting with can be a list of such ranges from a text box, separated by newlines, so I need to look at each line individually, get the count of represented IP address, and finally, how many of the submitted ranges have this condition.</p>

<pre><code>1.1.1.4-6     /* Represents 3 actual IP Addresses, need to know "3" */
2.2.3-10.255  /* Represents 8 actual IP Addresses, need to   know "8" */
3.3.3.3       /* No ranges specified, skip this
4.4.4.4       /* No ranges specified, skip this
</code></pre>

<p>Net result is that I want to know is that 2 lines contained a "range", which represent 8 IP addresses (3+8)</p>

<p>Any eloquent solutions would be appreciated by my sleep schedule. :
)</p>
