PHPackages                             wikimedia/ip-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wikimedia/ip-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wikimedia/ip-utils
==================

Parse, match, and analyze IP addresses and CIDR ranges

6.0.1(3mo ago)7644.9k—4.3%7GPL-2.0-or-laterPHPPHP &gt;=8.1

Since Jun 25Pushed 2mo agoCompare

[ Source](https://github.com/wikimedia/mediawiki-libs-IPUtils)[ Packagist](https://packagist.org/packages/wikimedia/ip-utils)[ Docs](https://www.mediawiki.org/wiki/IPUtils)[ RSS](/packages/wikimedia-ip-utils/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (12)Used By (7)

[![Packagist](https://camo.githubusercontent.com/b5d7b04a9f66583c4ae7ae528d2839b4cd983dca3708bde84ca5ee96ba9b5562/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77696b696d656469612f69702d7574696c732e7376673f7374796c653d666c6174)](https://packagist.org/packages/wikimedia/ip-utils)

IPUtils
=======

[](#iputils)

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

Additional documentation about the library can be found on [mediawiki.org](https://www.mediawiki.org/wiki/IPUtils).

Usage
-----

[](#usage)

```
use Wikimedia\IPUtils;

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

`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( [
    '208.80.154.0/26',
    '2620:0:861:1::/64',
    '10.64.0.0/22',
] );

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

Performance
-----------

[](#performance)

In rough benchmarking, IPSet takes about 80% more time than `in_array()` checks on a short (a couple hundred at most) array of addresses. It's fast either way at those levels, though, and IPSet would scale better than in\_array if the array were much larger.

For mixed-family CIDR sets, however, `IPSet::match()` gives well over 100x speedup compared to iterating `IPUtils::isInRange()` over an array of CIDR specs.

The basic implementation is two separate binary trees (IPv4 and IPv6) as nested PHP arrays with keys named 0 and 1. The values false and true are terminal match-fail and match-success; otherwise, the value is a deeper node in the tree.

A simple depth-compression scheme is also implemented: whole-byte tree compression at whole-byte boundaries only, where no branching occurs during that whole byte of depth. A compressed node has keys 'comp' (the byte to compare) and 'next' (the next node to recurse into if 'comp' matched successfully).

For example, given these inputs:

```
25.0.0.0/9
25.192.0.0/10
```

The v4 tree would look like:

```
root4 => [
    'comp' => 25,
    'next' => [
        0 => true,
        1 => [
            0 => false,
            1 => true,
        ],
    ],
];
```

(multi-byte compression nodes were attempted as well, but were a net loss in my test scenarios due to additional match complexity)

Running tests
-------------

[](#running-tests)

```
composer install --prefer-dist
composer test

```

History
-------

[](#history)

The IPUtils class started life in 2006 as part of [MediaWiki 1.7](https://www.mediawiki.org/wiki/MediaWiki_1.7) ([r15572](https://www.mediawiki.org/wiki/Special:Code/MediaWiki/15572)). It was split out of the MediaWiki codebase and published as an independent library during the [MediaWiki 1.34](https://www.mediawiki.org/wiki/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](https://gerrit.wikimedia.org/r/131758)). It was moved to a library during the MediaWiki 1.26 development cycle ([change 221179](https://gerrit.wikimedia.org/r/221179), [change 218384](https://gerrit.wikimedia.org/r/218384)).

###  Health Score

59

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity42

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~240 days

Recently: every ~364 days

Total

11

Last Release

115d ago

Major Versions

1.0.0 → 2.0.02020-03-09

2.x-dev → 3.0.02020-11-09

3.0.2 → 4.0.02022-01-29

4.0.1 → 5.0.02023-09-28

5.0.0 → 6.0.02025-11-21

PHP version history (4 changes)1.0.0PHP &gt;=5.6.99

2.0.0PHP &gt;=7.2.9

5.0.0PHP &gt;=7.4.3

6.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

![](https://www.gravatar.com/avatar/f281fc1a5701e1e7002129e0198e12bff5c8ce049377bf1f75b022d588a5bd94?d=identicon)[legoktm](/maintainers/legoktm)

---

Top Contributors

[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (54 commits)")[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (19 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (16 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (14 commits)")[![atdt](https://avatars.githubusercontent.com/u/376462?v=4)](https://github.com/atdt "atdt (14 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (6 commits)")[![Ammarpad](https://avatars.githubusercontent.com/u/45658045?v=4)](https://github.com/Ammarpad "Ammarpad (2 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (2 commits)")[![plstand](https://avatars.githubusercontent.com/u/762731?v=4)](https://github.com/plstand "plstand (1 commits)")[![RazeSoldier](https://avatars.githubusercontent.com/u/29511518?v=4)](https://github.com/RazeSoldier "RazeSoldier (1 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (1 commits)")[![blblack](https://avatars.githubusercontent.com/u/1015349?v=4)](https://github.com/blblack "blblack (1 commits)")[![ZabeMath](https://avatars.githubusercontent.com/u/35405030?v=4)](https://github.com/ZabeMath "ZabeMath (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-ip-utils/health.svg)

```
[![Health](https://phpackages.com/badges/wikimedia-ip-utils/health.svg)](https://phpackages.com/packages/wikimedia-ip-utils)
```

###  Alternatives

[loveorigami/yii2-plugins-system

Plugins system as WP for Yii2

1143.0k1](/packages/loveorigami-yii2-plugins-system)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
