Parse, inspect and test IP addresses

v0.1.7 2024-04-26 11:23 UTC

This package is auto-updated.

Last update: 2024-07-17 12:59:18 UTC


PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

Parse, inspect and test IP addresses

Compass provides an accurate disassembly of both v4 and v6 IP addresses and the means to inspect and compare them.

Get news and updates on the DecodeLabs blog.


Install via Composer:

composer require decodelabs/compass


Parse IP strings, integers and binaries and inspect them:

use DecodeLabs\Compass\Ip;

$ip = Ip::parse('');

if($ip->isV4()) {
    // Do something

if($ip->isLoopback()) {
    // Do something else

$v6Hybrid = $ip->toV6(); // ::ffff:

$v6 = Ip::parse('fe80:0:0:0:202:b3ff:fe1e:8329');

if($ip->isV6()) {
    // The future

Check to see if an IP is within a range:

if($ip->isIn('')) {} // CIDR
if($ip->isIn('')) {} // Netmask
if($ip->isIn('')) {} // Range
if($ip->isIn('')) {} // Relative range
if($ip->isIn('127.0.0.*')) {} // Wildcards

if($v6->isIn('fe80:0:0:0:202:b3ff:fe1e:0/128')) {} // CIDR
if($v6->isIn('fe80:0:0:0:202:b3ff:fe1e:0-fe80:0:0:0:202:b3ff:fe1e:ffff')) {} // Range
if($v6->isIn('fe80:0:0:0:202:b3ff:fe1e:0+9999')) {} // Relative range
if($v6->isIn('fe80:0:0:0:202:b3ff:fe1e:*')) {} // Wildcards


Compass is licensed under the MIT License. See LICENSE for the full license text.