S1lentium / IPTools

PHP Library for manipulating network addresses (IPv4 and IPv6)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does anyone understand delirium?

mickaelmonsieur opened this issue · comments

Hi,
Look this sample from the example please...

`Exclude Subnet from Network:

$excluded = Network::parse('192.0.0.0/8')->exclude(new Network('192.168.1.0/24'));
foreach($excluded as $network) {
echo (string)$network . '
';
}

192.0.0.0/9
192.128.0.0/11
192.160.0.0/13
192.168.0.0/24
192.168.2.0/23
...
192.192.0.0/10
`

If I read correctly, parse a block of 16,777,216 IPs, we extract 255 IPs, and the result is random blocks?!?!? /11 /13 /24 /23 ?!?!?

Or is the delirium? I find it hard to follow the joke ...?

regards,

If I read correctly, parse a block of 16,777,216 IPs, we extract 255 IPs, and the result is random blocks?!?!? /11 /13 /24 /23 ?!?!?

It's not random. If you imagine this output in range, we have the following:
192.0.0.0-192.168.0.255 and 192.168.2.0-192.255.255.255. As you can see, this range have 16776960 IPs in 2 disjunct network blocks. Now try to parse range 192.0.0.0-192.168.0.255 and 192.168.2.0-192.255.255.255 to CIDR format. In output you can see:
192.0.0.0/9
192.128.0.0/11
192.160.0.0/13
192.168.0.0/24
for 192.0.0.0-192.168.0.255

and:
192.168.2.0/23
192.168.4.0/22
192.168.8.0/21
192.168.16.0/20
192.168.32.0/19
192.168.64.0/18
192.168.128.0/17
192.169.0.0/16
192.170.0.0/15
192.172.0.0/14
192.176.0.0/12
192.192.0.0/10
for 192.168.2.0-192.255.255.255.

If we sum all of these blocks, it is equal to 16776960 IPs, which does not have 256 IPs.
This is not delirium :)