PHP code example of grntartaglia / netmask

1. Go to this page and download the library: Download grntartaglia/netmask 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/ */

    

grntartaglia / netmask example snippets


$block = new Netmask\Netmask('192.168.0.1/24');
$block->base;                       // 192.168.0.0
$block->mask;                       // 255.255.255.0
$block->bitmask;                    // 24
$block->hostmask;                   // 0.0.0.255
$block->broadcast;                  // 192.168.0.255
$block->size;                       // 256
$block->first;                      // 192.168.0.1
$block->last;                       // 192.168.0.254

$block->contains('192.168.0.7/24'); // true
$block->contains('192.168.0.126');  // true
$block->contains('192.168.1.1');    // false

// ['192.168.0.1', '192.168.0.2', '192.168.0.3', ...]
$block->getAll();

foreach ($block->getAll() as $ip) {
    // IP: 192.168.0.x
}

new Netmask('192.168.0.1/24');            // The preferred form.
new Netmask('192.168.0.1');               // A /32 block.
new Netmask('192.168.0.1/255.255.255.0');