PHP code example of markrogoyski / ipv4-subnet-calculator
1. Go to this page and download the library: Download markrogoyski/ipv4-subnet-calculator 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/ */
markrogoyski / ipv4-subnet-calculator example snippets
reate from CIDR notation
$subnet = IPv4\Subnet::fromCidr('192.168.1.0/24');
// Get network information
echo $subnet->networkAddress(); // 192.168.1.0
echo $subnet->broadcastAddress(); // 192.168.1.255
echo $subnet->hostCount(); // 254
// Check if an IP is in the subnet
$subnet->containsIP('192.168.1.100'); // true
// From CIDR notation (simple)
$subnet = IPv4\Subnet::fromCidr('192.168.1.0/24');
$subnet = new IPv4\Subnet('192.168.1.0', 24);
// From subnet mask
$subnet = IPv4\SubnetParser::fromMask('192.168.1.0', '255.255.255.0');
// From IP range
$subnet = IPv4\SubnetParser::fromRange('192.168.1.0', '192.168.1.255');
// From host count