Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 1.62 KB

README.md

File metadata and controls

60 lines (42 loc) · 1.62 KB

The CIDR library for create CIDR's from IP range.

Build Status PHP from Packagist Version Coverage Status License

CIDR - Classless Inter-Domain Routing. Wiki

Installing CIDR Library

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'
}