1. Go to this page and download the library: Download arokettu/ip-address 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/ */
arokettu / ip-address example snippets
use Arokettu\IP\IPAddress;
use Arokettu\IP\IPBlock;
use Arokettu\IP\IPv4Address;
use Arokettu\IP\IPv4Block;
use Arokettu\IP\IPv6Address;
use Arokettu\IP\IPv6Block;
use Arokettu\IP\Tools\CompareHelper;
use Arokettu\IP\Tools\BlockOptimizer;
// IP address
$ip4 = IPv4Address::fromString('140.82.121.4');
$ip6 = IPv6Address::fromString('2606:4700:90:0:f22e:fbec:5bed:a9b9');
$ipAuto = IPAddress::fromString('172.65.251.78'); // IPv4Address in this case
// IP Block
$block4 = IPv4Block::fromString('140.82.112.0/20'); // CIDR string
$block6 = IPv6Block::fromString('2606:4700::', 32); // Base IP and prefix length
$blockAuto = IPBlock::fromString('fe80::/10'); // IPv6Block in this case
// Containment
// If block contains IP
$block4->contains($ip4); // true
// If block contains other block
$block6->contains($blockAuto); // false
// Sort helper
$ips = [/* IP Addresses */];
usort($ips, CompareHelper::nonStrictCompare(...)); // allows to mix v4 and v6
// Block collapser
$blocks = [
IPv4Block::fromString('127.0.0.0/24'),
IPv4Block::fromString('127.0.0.0/16'),
IPv4Block::fromString('192.168.0.0/24'),
IPv4Block::fromString('192.168.1.0/24'),
];
$optimized = BlockOptimizer::optimizeV4(...$blocks); // [127.0.0.0/16, 192.168.0.0/23]
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.