PHP code example of luzrain / ipcalc

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

    

luzrain / ipcalc example snippets


$net = new IPCalc\IP('192.168.1.1/24');
// or
$net = new IPCalc\IP('192.168.1.1', 24);

$net->getIp();                  // 192.168.1.1    // The original IP address
$net->getNetmask();             // 255.255.255.0  // Subnet mask
$net->getCidr();                // 24             // CIDR prefix length
$net->getVersion();             // 4              // IP version (4 or 6)
$net->isPrivate();              // true           // Returns true if the IP address is in a private range
$net->getNetwork();             // 192.168.1.0    // Network address of the subnet (IPv4 only)
$net->getBroadcast();           // 192.168.1.255  // Broadcast address of the network (IPv4 only)
$net->getHostMin();             // 192.168.1.1    // First usable IP address in the subnet
$net->getHostMax();             // 192.168.1.254  // Last usable IP address in the subnet
$net->contains('192.168.1.10'); // true           // Returns true if the given IP address is within the network