Use
Net::CIDR's
cidr2range, sort the ranges, combine the ones that are overlapping or adjacent, then use
range2cidr to go back.
-- Randal L. Schwartz, Perl hacker
update
Shoot, I totally missed
cidradd in the same module, which does precisely that!
$ perl
use Net::CIDR qw(cidradd);
print join (", ", cidradd(qw{
209.152.214.112/30
209.152.214.116/31
209.152.214.118/31
})), "\n"
^D
209.152.214.112/29
$ perl
use Net::CIDR qw(cidradd);
print join (", ", cidradd(qw{
209.152.214.112/31
209.152.214.116/31
209.152.214.118/31
})), "\n"
^D
209.152.214.112/31, 209.152.214.116/30