PHP code example of hiqdev / php-ip-tools

1. Go to this page and download the library: Download hiqdev/php-ip-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hiqdev / php-ip-tools example snippets


$block = '192.168.0.0/24';
$taken = ['192.168.0.64/28'];

$calculator = new IpBlocksCalculator();
$free = $calculator->__invoke($block, $taken);

var_dump($free);
/*
 *  [
 *    '192.168.0.0/26',
 *    '192.168.0.80/28',
 *    '192.168.0.96/27',
 *    '192.168.0.128/25',
 *   ]
 */

IpRangeParser::fromString('192.0.2.[1,2,100-250]/24');
// ['192.0.2.1/24', '192.0.2.2/24', '192.0.2.100/24' ... '192.0.2.250/24']