Answer the question
In order to leave comments, you need to log in
Does anyone know a good library for converting an IP range to CIDR(s)?
I can't find a normal PHP library to convert a range of IP addresses to CIDRs (or CIDRs). That is, give it an input, for example, 10.0.23.40-10.0.25.241
and get something like the output
10.0.23.40/29
10.0.23.48/28
10.0.23.64/26
10.0.23.128/25
10.0.24.0/24
10.0.25.0/25
10.0.25.128/26
10.0.25.192/27
10.0.25.224/28
10.0.25.240/31
Answer the question
In order to leave comments, you need to log in
https://github.com/S1lentium/IPTools
Able to solve a wide range of tasks that arise when working with addresses, subnets, and so on.
$range_str = '10.0.23.40-10.0.25.241';
$networks = IPTools\Range::parse($range_str)->getNetworks();
foreach($networks as $network)
{
echo (string)$network."\n";
}
Write yourself, this is a simple task
- see how many zero bits are at the end of the address -> glue ADDRESS / HOW MANY BITS -
turn all these bits into ones. Add 1.
-repeat until you pass the entire range.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question