PHPackages                             yuninternet/php-ip-calculator - 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. yuninternet/php-ip-calculator

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

yuninternet/php-ip-calculator
=============================

IP calculator written in PHP 7.0, IPv4 &amp; IPv6 are supported, mainly functions for subnet allocation.

v0.0.13(7y ago)693↓100%3MITPHPPHP &gt;=7.0.0

Since Mar 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/yzslab/php-ip-calculator)[ Packagist](https://packagist.org/packages/yuninternet/php-ip-calculator)[ RSS](/packages/yuninternet-php-ip-calculator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (11)Used By (0)

PHP IP Calculator
=================

[](#php-ip-calculator)

IPv4 &amp; IPv6 support.

More features is being developed.

Install
-------

[](#install)

```
composer require yuninternet/php-ip-calculator

```

Usage
-----

[](#usage)

```
$factory = new YunInternet\PHPIPCalculator\CalculatorFactory("192.168.111.222/16");

```

or

```
$factory = new YunInternet\PHPIPCalculator\CalculatorFactory("2001:470:0:76::2/48");

```

then

```
$calculator = $factory->create();

$calculator->getType();
$calculator->getFirstHumanReadableAddress();
$calculator->getLastHumanReadableAddress();

// v4
// Is the target IP in this subnet?
$calculator->isIPInRange("192.168.111.111"); // true;
$calculator->isIPInRange("192.169.111.111"); // false;

// If seperate this subnet to smaller subnet, what is the n subnet's first ip?
$calculator::calculable2HumanReadable($calculator->ipAt(0)); // 192.168.0.0
$calculator::calculable2HumanReadable($calculator->ipAt(65535)); // 192.168.255.255
$calculator::calculable2HumanReadable($calculator->ipAt(255, 24)); // 192.168.255.0;
// Or from then last one to the first.
$calculator::calculable2HumanReadable($calculator->ipReverseAt(255, 24)); // 192.168.0.0
$calculator::calculable2HumanReadable($calculator->ipReverseAt(1, 24)); // 192.168.254.0

// Is the n out of range?
$calculator->isPositionOutOfRange(65535); // false
$calculator->isPositionOutOfRange(255, 24); // false
$calculator->isPositionOutOfRange(256, 24); // true

// Which subnet after this subnet?
$calculator->getSubnetAfter()->getFirstHumanReadableAddress(); // 192.169.0.0
$calculator->getSubnetAfter(87)->getFirstHumanReadableAddress(); // 192.255.0.0
// Or before this subnet?
$calculator->getSubnetBefore()->getFirstHumanReadableAddress(); // 192.167.0.0
$calculator->getSubnetBefore(168)->getFirstHumanReadableAddress(); // 192.0.0.0

// Is the IP1 after IP2?
$calculator::compare($calculator::humanReadable2Calculable("127.0.0.1"), $calculator::humanReadable2Calculable("127.0.0.2")); // -1
$calculator::compare($calculator::humanReadable2Calculable("127.0.0.1"), $calculator::humanReadable2Calculable("127.0.0.1")); // 0
$calculator::compare($calculator::humanReadable2Calculable("127.0.0.2"), $calculator::humanReadable2Calculable("127.0.0.1")); // 1

// After how many subnet is the destination subnet
$calculator->distanceTo($calculator->getSubnetAfter(100); // 100

// How many smaller subnet in this subnet?
$calculator->howMany(); // 65536
$calculator->howMany(24); // 256

// v6
$calculator->isIPInRange("2001:470:0:76::ff0f:f0ff"); // true;
$calculator->isIPInRange("2001:460:0:78::ffff:ffff"); // false;

$calculator::calculable2HumanReadable($calculator->ipAt(2)); // 2001:470::2
$calculator::calculable2HumanReadable($calculator->ipAt(65535, 64)); // 2001:470:0:ffff::
$calculator::calculable2HumanReadable($calculator->ipAt([
    0x0,
    0x0000FFFF,
    0xFFFFFFFF,
    0xFFFFFFFF,
])); // 2001:470:0:ffff:ffff:ffff:ffff:ffff

$calculator::calculable2HumanReadable($calculator->ipReverseAt(0)); // 2001:470:0:ffff:ffff:ffff:ffff:ffff
$calculator::calculable2HumanReadable($calculator->ipReverseAt([
    0x0,
    0x0000FFFF,
    0xFFFFFFFF,
    0xFFFFFFFF,
])); // 2001:470::

$calculator->isPositionOutOfRange([
    0x0,
    0x0000FFFF,
    0xFFFFFFFF,
    0xFFFFFFFF,
]); // false
$calculator->isPositionOutOfRange(65535, 64); // false
$calculator->isPositionOutOfRange(65536, 64); // true

$calculator->getSubnetAfter()->getFirstHumanReadableAddress(); // 2001:470:1::
$calculator->getSubnetAfter(0xffff)->getFirstHumanReadableAddress(); // 2001:470:ffff::

$calculator->getSubnetBefore()->getFirstHumanReadableAddress(); // 2001:46f:ffff::
$calculator->getSubnetBefore(0x4700000)->getFirstHumanReadableAddress(); // 2001::

$calculator::compare($calculator::humanReadable2Calculable("::1"), $calculator::humanReadable2Calculable("::2")); // -1
$calculator::compare($calculator::humanReadable2Calculable("::1"), $calculator::humanReadable2Calculable("::1")); // 0
$calculator::compare($calculator::humanReadable2Calculable("::2"), $calculator::humanReadable2Calculable("::1")); // 1

$calculator->distanceTo($calculator->getSubnetAfter(100); // [0, 0, 0, 100]

$calculator->howMany(48); // [0, 0, 0, 1]
$calculator->howMany(64); // [0, 0, 0, 65536]

```

For more details, please look at test located in tests/YunInternet/PHPIPCalculator/Test:

```
phpunit

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

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

Total

10

Last Release

2615d ago

### Community

Maintainers

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

---

Top Contributors

[![yzslab](https://avatars.githubusercontent.com/u/564361?v=4)](https://github.com/yzslab "yzslab (25 commits)")

---

Tags

phpipv6IPcalculatoripv4subnet

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yuninternet-php-ip-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/yuninternet-php-ip-calculator/health.svg)](https://phpackages.com/packages/yuninternet-php-ip-calculator)
```

###  Alternatives

[s1lentium/iptools

PHP Library for manipulating network addresses (IPv4 and IPv6)

2446.2M24](/packages/s1lentium-iptools)[markrogoyski/ipv4-subnet-calculator

Network calculator for subnet mask and other classless (CIDR) network information.

177813.7k6](/packages/markrogoyski-ipv4-subnet-calculator)[longman/ip-tools

PHP IP Tools for manipulation with IPv4 and IPv6

147245.6k6](/packages/longman-ip-tools)[mlocati/ip-lib

Handle IPv4, IPv6 addresses and ranges

3126.4M44](/packages/mlocati-ip-lib)[rlanvin/php-ip

IPv4/IPv6 manipulation library for PHP

180738.8k11](/packages/rlanvin-php-ip)[tholu/php-cidr-match

CIDRmatch is a library to match an IP to an IP range in CIDR notation (IPv4 and IPv6).

37211.1k](/packages/tholu-php-cidr-match)

PHPackages © 2026

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