title: How to split specified network into subnets using Python
body: <p>I've been working on this question, but can't find a clearance.</p>
  
  <p>I have a Python script which should get two arguments - network/CIDR &amp; a number. The script should divide specified network to a number of parts, subnets, and show parameters of those subnets, like network address, broadcast, number of hosts.</p>
  
  <p>Actually, my current code state is <a href="https://github.com/eyablokov/subnet-divider/blob/master/subnet-divider.py" rel="nofollow noreferrer">here</a>, on GitHub.</p>
  
  <p>The reason I'm asking is there are other topic on Stack Overflow, like <a href="https://stackoverflow.com/questions/38864268/splitting-a-network-into-subnets-of-multiple-prefixes">this</a>, <a href="https://stackoverflow.com/questions/19420588/subnetting-to-split-network-into-smaller-networks">this</a> or <a href="https://stackoverflow.com/questions/19191608/how-to-divide-a-network-into-eleven-subnets">this</a>. But all of them have prefixes. And my point is, for example, <code>./subnet-divider.py 200.100.33.65/26 3</code>, so I should divide it into 3 subnets. Or <code>./subnet-divider.py 200.100.33.65/26 9</code>. So this is a different point, although slightly similar to discussed.</p>
  
  <p>I crossed around both modules - <a href="https://docs.python.org/3.6/library/ipaddress.html" rel="nofollow noreferrer">ipaddress</a> and <a href="https://netaddr.readthedocs.io/en/latest/api.html" rel="nofollow noreferrer">netaddr</a>. Both are similar. There are generators for subnetting, but they have arguments like <code>prefix</code>, required, and <code>count</code>, which is good.</p>
  
  <pre><code>In [22]: s.get_subnet(27, count=3)
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-22-5864cbfc587d&gt; in &lt;module&gt;()
  ----&gt; 1 s.get_subnet(27, count=3)
  
  /home/simple/Projects/subnet-divider/ip_splitter.py in get_subnet(self, prefix, count)
       14         """ . """
  
       15         for ip_network in self.get_available_ranges():
  ---&gt; 16             subnets = list(ip_network.subnet(prefix, count=count))
       17             if not subnets:
       18                 continue
  
  /usr/local/lib/python3.5/dist-packages/netaddr/ip/__init__.py in subnet(self, prefixlen, count, fmt)
     1269 
     1270         if not 1 &lt;= count &lt;= max_subnets:
  -&gt; 1271             raise ValueError('count outside of current IP subnet boundary!')
     1272 
     1273         base_subnet = self._module.int_to_str(self.first)
  
  ValueError: count outside of current IP subnet boundary!
  </code></pre>
  
  <p>Of course, that' correct.</p>
  
  <p>So, How can I divide? To do it flexible, I don't need a prefix, but the script should be able to divide incoming network onto specified subnets, 3, 7, 10, etc to the max.</p>
  
  <p>Thanks.</p>