CIDR - Classless Inter-Domain Routing. Wiki
The recommended way to install CIDR Library is through Composer.
# Install Composer
curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of CIDR Library:
composer require lionser/cidr
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
You can then later update CIDR Library using composer:
composer update
Usage example:
$netmaskDetectror = new \Lionser\Detector\NetmaskDetector();
$parser = new \Lionser\Parser\CIDRRangeParser($netmaskDetectror);
$start = new \Lionser\ValueObject\IP\IPv4('1.0.0.0');
$end = new \Lionser\ValueObject\IP\IPv4('1.0.0.255');
$range = new \Lionser\ValueObject\IP\Range($start, $end);
/** @var $cidrs \Lionser\ValueObject\CIDR[] */
$cidrs = $parser->parseRange($range);
# Or facade usage
/** @var $cidrs \Lionser\ValueObject\CIDR[] */
$cidrs = \Lionser\Parser\CIDRParserFacade::parse('1.0.0.0', '1.0.0.255');
foreach($cidrs as $cidr) {
echo $cidr; # '1.0.0.0\24'
}