PHPackages                             tomcan/subnet-parser - 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. tomcan/subnet-parser

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

tomcan/subnet-parser
====================

IP Subnet parser and merger/aggregator

1.3.0(3mo ago)037Apache-2.0PHP

Since Nov 9Pushed 3mo agoCompare

[ Source](https://github.com/TomCan/subnet-parser)[ Packagist](https://packagist.org/packages/tomcan/subnet-parser)[ Docs](https://github.com/tomcan/subnet-parser)[ RSS](/packages/tomcan-subnet-parser/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

TomCan\\SubnetParser
====================

[](#tomcansubnetparser)

TomCan's subnet parser and merger library can parse, merge/aggregate IP subnets into a structured `Subnet` object.

Usage
-----

[](#usage)

Add the library to your project using composer

```
composer require tomcan/subnet-parser

```

Then just instantiate it

```
$parser = new TomCan\SubnetParser\SubnetParser();
// Parse ranges into subnets
$subnets = $parser->parseRanges(['192.168.1.0/24', '192.168.2.0/24', '192.168.0.0/24']);
// Merge subnets
$subnets = $parser->mergeSubnets($subnets);
foreach ($subnets as $subnet) {
    echo 'Network: '.$subnet->network.'/'.$subnet->prefixlenght.PHP_EOL;
}
```

### Parsing

[](#parsing)

This library allows you to parse subnets in various notations. The library will try and figure it out.

```
192.168.0.1
-> 192.168.0.1/32
192.168.1.1/24
-> 192.168.1.0/24
192.168.2.1/255.255.255.0
-> 192.168.2.0/24
192.168.3.0-192.168.3.255
-> 192.168.3.0/24
192.168.4.0-192.168.5.128
-> 192.168.4.0/24 + 192.168.5.0/25 + 192.168.5.128/32

```

### Merging

[](#merging)

It can also merge an array of subnets into the least possible amount of subnets.

```
192.168.0.0/24
192.168.1.0/24
-> 192.168.0.0/23
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/25
192.168.3.128/25
-> 192.168.0.0/22

```

### The `Subnet` object

[](#the-subnet-object)

The `Subnet` object is a very simple but structured object containing the network address and prefix length. It also contains the last IP of the range, as well as the preceding IP (last IP of previous subnet) and the next IP (first IP of the next subnet). IPs are available in their textual representation, as well as in their packed format.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance80

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~20 days

Recently: every ~30 days

Total

7

Last Release

104d ago

### Community

Maintainers

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

---

Top Contributors

[![TomCan](https://avatars.githubusercontent.com/u/2892620?v=4)](https://github.com/TomCan "TomCan (15 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomcan-subnet-parser/health.svg)

```
[![Health](https://phpackages.com/badges/tomcan-subnet-parser/health.svg)](https://phpackages.com/packages/tomcan-subnet-parser)
```

###  Alternatives

[jzonta/faker-restaurant

Food and Beverage names generate using fakerphp/faker

96326.4k](/packages/jzonta-faker-restaurant)[php-composter/php-composter

Git Hooks Management through Composer.

10526.0k11](/packages/php-composter-php-composter)[spell-checker/spell-checker

Multi-language code and text spell checker in PHP

16192.0k1](/packages/spell-checker-spell-checker)[cobaltgrid/vatsim-stand-status

A PHP library to access the status of aircraft stands on VATSIM

198.8k](/packages/cobaltgrid-vatsim-stand-status)[tschucki/filament-workflows

Add workflows to your filament app

181.4k](/packages/tschucki-filament-workflows)

PHPackages © 2026

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