PHPackages                             dxw/cidr - 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. dxw/cidr

ActiveLibrary

dxw/cidr
========

IP address matching with CIDR ranges

v3.2.0(2y ago)6108.1k↓16.9%4[2 PRs](https://github.com/dxw/cidr/pulls)2MITPHPPHP ^7.4||^8.1CI passing

Since Sep 24Pushed 1y ago20 watchersCompare

[ Source](https://github.com/dxw/cidr)[ Packagist](https://packagist.org/packages/dxw/cidr)[ Docs](https://github.com/dxw/cidr)[ RSS](/packages/dxw-cidr/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (21)Used By (2)

cidr
====

[](#cidr)

PHP library for matching an IP address to a CIDR range.

Supports IPv4 and IPv6.

Installation
------------

[](#installation)

```
composer require dxw/cidr

```

Usage
-----

[](#usage)

To simply match two addresses:

```
$result = \Dxw\CIDR\IP::contains('2001:db8:123::/64', '2001:db8:123::42');
if ($result->isErr()) {
    // handle the error
}
$match = $result->unwrap();

if ($match) {
    echo "The addresses match!\n";
} else {
    echo "The addresses don't match.\n";
}

```

Notes
-----

[](#notes)

IPv4-compatible IPv6 addresses and IPv4-mapped IPv6 addresses are partially supported.

An address of the form `::127.0.0.1` or `::ffff:127.0.0.1` will be parsed. But only if they fall within `::/96` or `::ffff:0:0/96`. For example, `2001:db8::127.0.0.1` will be rejected.

But the resulting address will be treated as an IPv6 and as such it will never match an IPv4 address. For example, `127.0.0.1` will never match `::ffff:127.0.0.1` or `::127.0.0.1`.

API
---

[](#api)

Example of testing if an IPv6 address falls within a particular IPv6 range:

```
$result = \Dxw\CIDR\IPv6Range::Make('2001:db8:123::/64');
if ($result->isErr()) {
    // handle the error
}
$range = $result->unwrap();

$result = \Dxw\CIDR\IPv6Address::Make('2001:db8:123::42');
if ($result->isErr()) {
    // handle the error
}
$address = $result->unwrap();

if ($range->containsAddress($address)) {
    echo "It matches!\n";
} else {
    echo "It doesn't match.\n";
}

```

To make the example IPv4-only, replace `IPv6` with `IPv4`. To make the example version agnostic, replace `IPv6` with just `IP`.

- `IP`
    - `::contains(string $addressOrRange, string $address): \Dxw\Result\Result`
- `IPAddress`
    - `::Make(string $address): \Dxw\Result\Result` (`AddressBase` is the abstract superclass of `IPv4Address` and `IPv6Address`)
- `IPRange`
    - `::Make(string $range): \Dxw\Result\Result` (`RangeBase` is the abstract superclass of `IPv4Range` and `IPv6Range`)
- `IPv4Address`
    - `::Make(string $address): \Dxw\Result\Result`
    - `::FromBinary(\phpseclib\Math\BigInteger $binary): \Dxw\Result\Result`
    - `->__toString(): string`
    - `->getBinary(): \phpseclib\Math\BigInteger`
- `IPv6Address`
    - `::Make(string $address): \Dxw\Result\Result`
    - `::FromBinary(\phpseclib\Math\BigInteger $binary): \Dxw\Result\Result`
    - `->__toString(): string`
    - `->getBinary(): \phpseclib\Math\BigInteger`
- `IPv4Block`
    - `::Make(int $value): \Dxw\Result\Result`
    - `->__toString(): string`
    - `->getValue(): int`
    - `->getNetmask(): \phpseclib\Math\BigInteger`
- `IPv6Block`
    - `::Make(int $value): \Dxw\Result\Result`
    - `->__toString(): string`
    - `->getValue(): int`
    - `->getNetmask(): \phpseclib\Math\BigInteger`
- `IPv4Range`
    - `::Make(string $range): \Dxw\Result\Result`
    - `->__toString(): string`
    - `->getAddress(): \Dxw\CIDR\IPv4Address`
    - `->getBlock(): \Dxw\CIDR\IPv4Block`
    - `->containsAddress(\Dxw\CIDR\AddressBase $address): bool`
- `IPv6Range`
    - `::Make(string $range): \Dxw\Result\Result`
    - `->__toString(): string`
    - `->getAddress(): \Dxw\CIDR\IPv6Address`
    - `->getBlock(): \Dxw\CIDR\IPv6Block`
    - `->containsAddress(\Dxw\CIDR\AddressBase $address): bool`

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 76.9% of commits — single point of failure

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 ~371 days

Recently: every ~308 days

Total

8

Last Release

1008d ago

Major Versions

v1.0.0 → v2.0.02016-12-05

v2.0.0 → v3.0.02017-01-20

PHP version history (3 changes)v3.0.0PHP &gt;=7

v3.1.1PHP ^7.2

v3.2.0PHP ^7.4||^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/370665?v=4)[Rob Skilling](/maintainers/RobjS)[@RobjS](https://github.com/RobjS)

![](https://avatars.githubusercontent.com/u/1659723?v=4)[jkeasley](/maintainers/jkeasley)[@jkeasley](https://github.com/jkeasley)

![](https://avatars.githubusercontent.com/u/4721596?v=4)[Matthew Passmore](/maintainers/matpassmore)[@matpassmore](https://github.com/matpassmore)

![](https://avatars.githubusercontent.com/u/71827088?v=4)[Serena Piccioni](/maintainers/serena-piccioni)[@serena-piccioni](https://github.com/serena-piccioni)

---

Top Contributors

[![mallorydxw](https://avatars.githubusercontent.com/u/2256130?v=4)](https://github.com/mallorydxw "mallorydxw (83 commits)")[![RobjS](https://avatars.githubusercontent.com/u/370665?v=4)](https://github.com/RobjS "RobjS (18 commits)")[![snim2](https://avatars.githubusercontent.com/u/97674?v=4)](https://github.com/snim2 "snim2 (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![dxw-rails-user](https://avatars.githubusercontent.com/u/24606521?v=4)](https://github.com/dxw-rails-user "dxw-rails-user (1 commits)")

---

Tags

composergovpresspackagistphp

###  Code Quality

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dxw-cidr/health.svg)

```
[![Health](https://phpackages.com/badges/dxw-cidr/health.svg)](https://phpackages.com/packages/dxw-cidr)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k96.9M674](/packages/laravel-socialite)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.4k855.0k18](/packages/danog-madelineproto)[aporat/store-receipt-validator

PHP receipt validator for Apple App Store and Amazon Appstore

6503.9M9](/packages/aporat-store-receipt-validator)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)

PHPackages © 2026

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