I'd like to make a list of CIDR ranges that represent the addresses outside of the CIDR range I specify.
As a simplified example:
If I have the IP ranges from 8.8.8.8 to 8.8.8.10, I would be able to express this with CIDR ranges 8.8.8.8/31 and 8.8.8.10/32. But how could I express the opposite of these ranges in CIDR notation?
I'm new to CIDR so if this kind of tool exists already in a popular format please excuse my question.
As an additional note, I would like to eventually implement this filtering in R so if you can express your answer using R that would be preferable but I'm really mostly interested in how to build the algorithm to solve this kind of problem.
How many addresses does a CIDR block represent? You calculate 2 32-prefix , where prefix is the number after the slash. For example, /29 contains 232-29=23=8 addresses. Here's a quick table that you can reference for the most CIDR blocks.
The formula to calculate the number of assignable IP address to CIDR networks is similar to classful networking. Subtract the number of network bits from 32. Raise 2 to that power and subtract 2 for the network and broadcast addresses. For example, a /24 network has 232-24 - 2 addresses available for host assignment.
An easy way to understand CIDR is to think of the notation on the end as the amount of bits that will be allocated to the network. In this example “/24” would mean that the first 24 bits are allocated to the network (10101110.00010000. 00000000) and the remaining 8 bits would be allocated to the host (. 00000000).
CIDR is based on a concept called subnetting. Subnetting allows you to take a class, or block of IP addresses and further chop it up into smaller blocks or groups of IPs. CIDR and subnetting are virtually the same thing.
Basically, if you have a range (X, Y) of IP addresses and want to represent all IP addresses that are not in (X, Y) then it can be expressed as two ranges: (0.0.0.0, X-1) and (Y+1, 255.255.255.255).
Then you just convert the two ranges into CIDRs. A range may result in multiple CIDRs.
In the specific example you want ranges: (0.0.0.0, 8.8.8.7) and (8.8.8.11, 255.255.255.255). I have no idea of how to do this in R but here is a handy calculator here: http://www.ipaddressguide.com/cidr
(0.0.0.0, 8.8.8.7):
(8.8.8.11, 255.255.255.255):
8.8.8.11/32
8.8.8.12/30
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With