No description
Find a file
Daniel Baumann 0e189cda87
Releasing fastforward version 2.0.2-1~ffwd13+u1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2026-02-13 06:22:04 +01:00
.github/workflows Merging upstream version 2.0.2. 2026-02-13 06:21:45 +01:00
debian Releasing fastforward version 2.0.2-1~ffwd13+u1. 2026-02-13 06:22:04 +01:00
src Adding upstream version 2.0.1. 2026-02-13 06:21:21 +01:00
tests Merging upstream version 2.0.2. 2026-02-13 06:21:45 +01:00
.gitattributes Merging upstream version 2.0.2. 2026-02-13 06:21:45 +01:00
.gitignore Merging upstream version 2.0.2. 2026-02-13 06:21:45 +01:00
composer.json Merging upstream version 2.0.2. 2026-02-13 06:21:45 +01:00
LICENSE Adding upstream version 2.0.1. 2026-02-13 06:21:21 +01:00
phpunit.xml Merging upstream version 2.0.2. 2026-02-13 06:21:45 +01:00
README.md Merging upstream version 2.0.2. 2026-02-13 06:21:45 +01:00

Matomo/Network

Component providing Network tools.

PHPUnit

Installation

With Composer:

{
    "require": {
        "matomo/network": "*"
    }
}

Usage

IP

To manipulate an IP address, you can use the Matomo\Network\IP class:

$ip = IP::fromStringIP('127.0.0.1');
// IPv6
$ip = IP::fromStringIP('::1');
// In binary format:
$ip = IP::fromBinaryIP("\x7F\x00\x00\x01");

echo $ip->toString(); // 127.0.0.1
echo $ip->toBinary();

// IPv4 & IPv6
if ($ip instanceof IPv4) {}
if ($ip instanceof IPv6) {}

// Hostname reverse lookup
echo $ip->getHostname();

if ($ip->isInRange('192.168.1.1/32')) {}
if ($ip->isInRange('192.168.*.*')) {}

// Anonymize an IP by setting X bytes to null bytes
$ip->anonymize(2);

The Matomo\Network\IPUtils class provides utility methods:

echo IPUtils::binaryToStringIP("\x7F\x00\x00\x01");
echo IPUtils::stringToBinaryIP('127.0.0.1');

// Sanitization methods
$sanitizedIp = IPUtils::sanitizeIp($_GET['ip']);
$sanitizedIpRange = IPUtils::sanitizeIpRange($_GET['ipRange']);

// IP range
$bounds = IPUtils::getIPRangeBounds('192.168.1.*');
echo $bounds[0]; // 192.168.1.0
echo $bounds[1]; // 192.168.1.255

License

The Network component is released under the LGPL v3.0.