Functions to convert CIDR to IP range

0
Functions to convert CIDR to IP range
5 (100%) 2 votes

This is very short and simple functions to convert CIDR to IP ranges. This functions only apply to IP v4.

How to use it:
To convert CDIR to IP range, just use above functions to convert it. Below is an example:

If you want to verify the input before using the function

To get the full range as an array for a given IP (with or without CIDR Routing Prefix) you can use the following code but be careful because for example 25.25.25.25/16 return an array with 65536 elements and you can easily run out of memory using a smaller Routing Prefix

To fast check if a given ipv4 is matching a given CIDR you can do it inline like in this example

To fast check if a given ipv4 is matching a given array of IP (with or without CIDR Routing Prefix)

 

Share.

About Author

Leave A Reply