in reply to Unsorted IP Addr list to sorted IP list with ranges
from NetAddr::IP tutorial...
Optimising the address spaceThis is one of the reason for writing NetAddr::IP in the first place. Let's say you have a few chunks of IP space and you want to find the optimum CIDR representation for them. By optimum, I mean the least amount of CIDR subnets that exactly represent the given IP address space. The code below is an example of this:
use NetAddr::IP; push @addresses, NetAddr::IP->new($_) for <DATA>; print join(", ", NetAddr::IP::compact(@addresses)), "\n"; __DATA__ 10.0.0.0/18 10.0.64.0/18 10.0.192.0/18 10.0.160.0/19Which will, of course, output 10.0.0.0/17, 10.0.160.0/19, 10.0.192.0/18.
and also in the tutorial is enough to print those combined ranges in just about any format you can come up with.
|
|---|