PHPackages                             olragon/iptools - 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. olragon/iptools

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

olragon/iptools
===============

PHP Library for manipulating network addresses (IPv4 and IPv6)

0159PHP

Since May 22Pushed 11y ago1 watchersCompare

[ Source](https://github.com/olragon/IPTools)[ Packagist](https://packagist.org/packages/olragon/iptools)[ RSS](/packages/olragon-iptools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

IPTools
=======

[](#iptools)

IP Operations
-------------

[](#ip-operations)

```
$ip = new IP('192.168.1.1');
echo $ip->version;// IPv4
```

```
$ip = new IP('fc00::');
echo $ip->version; // IPv6
```

**Parsing IP from integer, binary and hex representation:**

```
echo (string)IP::parse(2130706433); // 127.0.0.1
echo (string)IP::parse('0b11000000101010000000000100000001') // 192.168.1.1
echo (string)IP::parse('0x0a000001'); // 10.0.0.1
```

or:

```
echo (string)IP::parseLong(2130706433); // 127.0.0.1
echo (string)IP::parseBin('11000000101010000000000100000001'); // 192.168.1.1
echo (string)IP::parseHex('0a000001'); // 10.0.0.1
```

**Converting IP to other formats:**

```
echo IP::parse('192.168.1.1')->bin // 11000000101010000000000100000001
echo IP::parse('10.0.0.1')->hex // 0a000001
echo IP::parse('127.0.0.1')->long // 2130706433
```

Networking
----------

[](#networking)

```
$network = new Network(new IP('192.168.1.1'), new IP('255.255.255.0'));
print_r($network->info);
```

```
Array
(
    [IP] => 192.168.1.1
    [netmask] => 255.255.255.0
    [network] => 192.168.1.0
    [prefixLength] => 24
    [CIDR] => 192.168.1.0/24
    [wildcard] => 0.0.0.255
    [broadcast] => 192.168.1.255
    [firstIP] => 192.168.1.0
    [lastIP] => 192.168.1.255
    [blockSize] => 256
    [firstHost] => 192.168.1.1
    [lastHost] => 192.168.1.254
    [hostsCount] => 254
)

```

```
echo Network::parse('192.0.0.1 255.0.0.0')->CIDR; // 192.0.0.0/8
echo (string)Network::parse('192.0.0.1/8')->netmask; // 255.0.0.0
echo (string)Network::parse('192.0.0.1'); // 192.0.0.1/32
```

**Iterate over Network`s Host-IPs:**

```
$network = Network::parse('192.168.1.0/24');
foreach($network as $ip) {
	echo (string)$ip . '';
}
```

```
192.168.1.1
...
192.168.1.254

```

**Excluding IP from Network:**

```
$excluded = Network::parse('192.0.0.0/8')->exclude(new IP('192.168.1.1'));
foreach($excluded as $network) {
	echo (string)$network . '';
}
```

```
192.0.0.0/9
192.128.0.0/11
192.160.0.0/13
192.168.0.0/24
192.168.1.0/32
192.168.1.2/31
...
192.192.0.0/10

```

**Excluding Subnet from Network:**

```
$excluded = Network::parse('192.0.0.0/8')->exclude(new Network('192.168.1.0/24'));
foreach($excluded as $network) {
	echo (string)$network . '';
}
```

```
192.0.0.0/9
192.128.0.0/11
192.160.0.0/13
192.168.0.0/24
192.168.2.0/23
...
192.192.0.0/10

```

**Count of Host-IPs**

```
echo count(Network::parse('192.168.1.0/24')) // 254
```

Range Operations
================

[](#range-operations)

**Defining a range in different formats:**

```
$range = new Range(new IP('192.168.1.0'), new IP('192.168.1.255'));
$range = Range::parse('192.168.1.0-192.168.1.255');
$range = Range::parse('192.168.1.*');
$range = Range::parse('192.168.1.0/24');
```

**Check if IP is within Range:**

```
echo Range::parse('192.168.1.1-192.168.1.254')->contains(new IP('192.168.1.5')); // true
echo Range::parse('::1-::ffff')->contains(new IP('::1234')); // true
```

**Iterating over Range IPs:**

```
$range = Range::parse('192.168.1.1-192.168.1.254');
foreach($range as $ip) {
	echo (string)$ip . '';
}
```

```
192.168.1.1
...
192.168.1.254

```

**Get Networks that fit into a specified range of IPs:**

```
$networks = Range::parse('192.168.1.1-192.168.1.254')->getNetworks();

foreach($networks as $network) {
	echo (string)$network . '';
}
```

```
192.168.1.1/32
192.168.1.2/31
192.168.1.4/30
192.168.1.8/29
192.168.1.16/28
192.168.1.32/27
192.168.1.64/26
192.168.1.128/26
192.168.1.192/27
192.168.1.224/28
192.168.1.240/29
192.168.1.248/30
192.168.1.252/31
192.168.1.254/32

```

**Count of IPs in Range**

```
echo count(Range::parse('192.168.1.1-192.168.1.254')) // 254
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 72.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/282f2e37d92c14a4f2dfbb5e1b1e22d7903613e845ec2a8d05687c77f1e4847d?d=identicon)[olragon](/maintainers/olragon)

---

Top Contributors

[![S1lentium](https://avatars.githubusercontent.com/u/2018277?v=4)](https://github.com/S1lentium "S1lentium (8 commits)")[![olragon](https://avatars.githubusercontent.com/u/47636?v=4)](https://github.com/olragon "olragon (3 commits)")

### Embed Badge

![Health badge](/badges/olragon-iptools/health.svg)

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

###  Alternatives

[cron/cron-bundle

Symfony cron

1901.5M2](/packages/cron-cron-bundle)[geoffreyrose/us-holidays

US Holidays Wrapper for the Carbon DateTime Library.

62717.0k2](/packages/geoffreyrose-us-holidays)[unleash/symfony-client-bundle

38443.5k](/packages/unleash-symfony-client-bundle)[elabx/fieldtype-recurring-dates

Field to setup recurring dates using RRule

104.2k](/packages/elabx-fieldtype-recurring-dates)

PHPackages © 2026

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