Play, analyze, parse, and match IP addresses and CIDR ranges

4.0.1 2023-09-20 23:26 UTC

This package is auto-updated.

Last update: 2023-09-25 08:40:27 UTC




Play, analyze, parse, and match IP addresses and CIDR ranges. This library supports both IPv4 and IPv6.

Additional documentation about the library can be found on


use Wikimedia\IPUtils;

IPUtils::isIPAddress( '::1' );
IPUtils::isIPv4( '' );

IPSet can be up to 100x faster than calling IPUtils::isInRange() over multiple CIDR specs.

use Wikimedia\IPSet;

// This will calculate an optimized data structure for the set
$ipset = new IPSet( [
] );

// Run fast checks against the same re-usable IPSet object
if ( $ipset->match( $ip ) ) {
    // ...

Running tests

composer install --prefer-dist
composer test


The IPUtils class started life in 2006 as part of [MediaWiki 1.7][] ([r15572][]). It was split out of the MediaWiki codebase and published as an independent library during the [MediaWiki 1.34][] development cycle.

The IPSet class was created by Brandon Black in 2014 as faster alternative to IPUtils::isInRange() (MediaWiki 1.24, change 131758). It was moved to a library during the MediaWiki 1.26 development cycle (change 221179, change 218384).