Skip to content
/ CIDR Public

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

License

Notifications You must be signed in to change notification settings

lionser/CIDR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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