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

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

artemeon/iptools
================

PHP Library for manipulating network addresses (IPv4 and IPv6)

v3.0.0(1y ago)174.4k—10%MITPHPPHP &gt;=8.4

Since Aug 9Pushed 1y agoCompare

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

READMEChangelog (1)Dependencies (7)Versions (5)Used By (0)

IPTools
=======

[](#iptools)

PHP Library for manipulating network addresses (IPv4 and IPv6).

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

[](#installation)

Composer: Run in command line:

```
composer require s1lentium/iptools

```

or put in composer.json:

```
{
    "require": {
        "s1lentium/iptools": "*"
    }
}
```

Usage
-----

[](#usage)

### 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:**

```
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
```

#### Other public properties:

[](#other-public-properties)

`maxPrefixLength`The max number of bits in the address representation: 32 for IPv4, 128 for IPv6.

`octetsCount`The count of octets in IP address: 4 for IPv4, 16 for IPv6

`reversePointer`The name of the reverse DNS PTR for the address:

```
echo new IP::parse('192.0.2.5')->reversePointer // 5.2.0.192.in-addr.arpa
echo new IP::parse('2001:db8::567:89ab')->reversePointer // b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa
```

### Network Operations

[](#network-operations)

```
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
```

**Exclude 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

```

**Exclude 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

```

**Split network into equal subnets**

```
$networks = Network::parse('192.168.0.0/22')->moveTo('24');
foreach ($networks as $network) {
	echo (string)$network . '';
}
```

```
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24

```

**Iterate over Network IP adresses:**

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

```
192.168.1.0
...
192.168.1.255

```

**Get Network hosts adresses as Range:**

```
$hosts = Network::parse('192.168.1.0/24')->hosts // Range(192.168.1.1, 192.168.1.254);
foreach($hosts as $ip) {
	echo (string)$ip . '';
}
```

```
192.168.1.1
...
192.168.1.254

```

**Count Network IP adresses**

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

### Range Operations

[](#range-operations)

**Define the 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
```

**Iterate over Range IP adresses:**

```
$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 IP Adresses:**

```
$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 IP adresses in Range**

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

License
=======

[](#license)

The library is released under the [MIT](https://opensource.org/licenses/MIT).

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance42

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 75.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 ~456 days

Total

3

Last Release

466d ago

Major Versions

v2.0.0 → 3.x-dev2025-02-07

PHP version history (2 changes)v2.0.0PHP &gt;=8.0

3.x-devPHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c87366e3237b8eed0a163e8a3c14a76418d7a82d34911d205585457a361ea8d?d=identicon)[artemeon](/maintainers/artemeon)

---

Top Contributors

[![S1lentium](https://avatars.githubusercontent.com/u/2018277?v=4)](https://github.com/S1lentium "S1lentium (60 commits)")[![grongor](https://avatars.githubusercontent.com/u/972493?v=4)](https://github.com/grongor "grongor (6 commits)")[![chriskapp](https://avatars.githubusercontent.com/u/2505846?v=4)](https://github.com/chriskapp "chriskapp (3 commits)")[![bartvanhoutte](https://avatars.githubusercontent.com/u/4867154?v=4)](https://github.com/bartvanhoutte "bartvanhoutte (3 commits)")[![petski](https://avatars.githubusercontent.com/u/116610?v=4)](https://github.com/petski "petski (2 commits)")[![wdjwxh](https://avatars.githubusercontent.com/u/3990956?v=4)](https://github.com/wdjwxh "wdjwxh (1 commits)")[![clayfreeman](https://avatars.githubusercontent.com/u/182658?v=4)](https://github.com/clayfreeman "clayfreeman (1 commits)")[![eugenekkh](https://avatars.githubusercontent.com/u/8081158?v=4)](https://github.com/eugenekkh "eugenekkh (1 commits)")[![jippi](https://avatars.githubusercontent.com/u/22841?v=4)](https://github.com/jippi "jippi (1 commits)")[![simPod](https://avatars.githubusercontent.com/u/327717?v=4)](https://github.com/simPod "simPod (1 commits)")

---

Tags

ipv6IPnetworkipv4cidrsubnetIP-Tools

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  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)[mlocati/ip-lib

Handle IPv4, IPv6 addresses and ranges

3126.4M44](/packages/mlocati-ip-lib)[longman/ip-tools

PHP IP Tools for manipulation with IPv4 and IPv6

147245.6k6](/packages/longman-ip-tools)[rlanvin/php-ip

IPv4/IPv6 manipulation library for PHP

180738.8k11](/packages/rlanvin-php-ip)[jaaulde/php-ipv4

PHP classes for working with IPV4 addresses and networks.

1034.6k](/packages/jaaulde-php-ipv4)

PHPackages © 2026

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