python - subtracting ranges from bigger ranges
<p>The problem I have is that I basically would like to find if there are any free subnets between a BGP aggregate-address (ex: <code>10.76.32.0 255.255.240.0</code>) and all the network commands on the same router (ex: <code>10.76.32.0 255.255.255.0, 10.76.33.0 255.255.255.0</code>)</p>

<p>In the above example, <code>10.76.34.0</code> -> <code>10.76.47.255</code> would be free.</p>

<p>I'm thinking of tackling this problem by converting the IP addresses and subnet masks to binary and subtracting that way.</p>

<p>To keep it simple I will keep this example in decimal but doing this would leave me with the following problem: let's say I have a range from 1 to 250, I subtract from this a smaller range that goes from 20 to 23, I would like to end up with a range from 1 to 19 and 24 to 250.</p>

<p>Using the range command doesn't really give me the expected results and while I could possibly create a list with every item in the range and subtract another list with a sub-set of items, it seems to me that it might not be a good idea to have lists with possibly tens of thousands of elements.</p>

<p>Hunor</p>