I’m updating an old Perl script to Ruby and having a problem with finding a replacement for one Perl library.
In the Perl script we use Net::CIDR::Lite, which takes a start and end ip address range and outputs a CIDR string.
This is a Perl example that shows the functionality:
#!/usr/bin/perl
use Net::CIDR::Lite;
$cidrblocks = Net::CIDR::Lite->new;
$cidrblocks->add_range("109.152.0.0-109.152.7.255");
$coveragezone = "";
@cidrlist = $cidrblocks->list();
$cidrcount=0;
while ( defined $cidrlist[$cidrcount] ) {
$coveragezone .= "$cidrlist[$cidrcount]";
}
continue {
$cidrcount++;
}
print "$coveragezone";
This script returns a string:
=> 109.152.0.0/21
Does anyone know of a Ruby lib or gem I could use to duplicate the functionality of the add_range call?
$cidrblocks = Net::CIDR::Lite->new;
$cidrblocks->add_range("109.152.0.0-109.152.7.255");
I found a ruby module which does this translation see
http://wejn.org/stuff/cidr.rb.html
have included it in my rails app and it’s perfect