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

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

s1lentium/iptools
=================

PHP Library for manipulating network addresses (IPv4 and IPv6)

v1.2.0(3y ago)2446.2M—4.8%56[8 PRs](https://github.com/S1lentium/IPTools/pulls)20MITPHPPHP ^8.0

Since Jul 27Pushed 2y ago15 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (7)Used By (20)

IPTools
=======

[](#iptools)

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

[![Build Status](https://camo.githubusercontent.com/796376620f763a6d223a23bb83577706703f11d59bc97ecf9a0841f8788769b3/68747470733a2f2f7472617669732d63692e6f72672f53316c656e7469756d2f4950546f6f6c732e737667)](https://travis-ci.org/S1lentium/IPTools)[![Coverage Status](https://camo.githubusercontent.com/dc82f4fef751076989da79ee1157abf8f23eced743233ceb90e04113b4774a99/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f53316c656e7469756d2f4950546f6f6c732f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/S1lentium/IPTools?branch=master)[![Code Climate](https://camo.githubusercontent.com/634341b8c13124934a746b18219259109f13cba702395caa9ae74aabe05a0ca1/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f53316c656e7469756d2f4950546f6f6c732f6261646765732f6770612e737667)](https://codeclimate.com/github/S1lentium/IPTools)

[![PHP 5.6](https://camo.githubusercontent.com/cc4f7ec05527d78bca32026f288b38eb12c861d1a7bdfb192d56a8742a05e2bb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e362d3838393242462e737667)](http://php.net)[![PHP 7.0](https://camo.githubusercontent.com/de3caf721d9573c21b80a8ae09dbc79aebb5fef439bf68edc82b1e22aa98c6ec/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302d3838393242462e737667)](http://php.net)[![PHP 8.0](https://camo.githubusercontent.com/4afe2c4966601dd5faed9969d33bf212610bac1eeda81a54b757dcf9fcd53f40/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302d3838393242462e737667)](http://php.net)

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

51

—

FairBetter than 96% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity64

Solid adoption and visibility

Community37

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 77.5% 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 ~515 days

Recently: every ~610 days

Total

6

Last Release

1370d ago

Major Versions

v0.9.0 → v1.0.02015-12-11

v1.1.0 → v2.x-dev2016-08-25

PHP version history (3 changes)v0.9.0PHP &gt;=5.3.0

v1.0.0PHP &gt;=5.4.0

v1.2.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2018277?v=4)[Safarov Alisher](/maintainers/S1lentium)[@S1lentium](https://github.com/S1lentium)

---

Top Contributors

[![S1lentium](https://avatars.githubusercontent.com/u/2018277?v=4)](https://github.com/S1lentium "S1lentium (62 commits)")[![grongor](https://avatars.githubusercontent.com/u/972493?v=4)](https://github.com/grongor "grongor (6 commits)")[![bartvanhoutte](https://avatars.githubusercontent.com/u/4867154?v=4)](https://github.com/bartvanhoutte "bartvanhoutte (3 commits)")[![digibeuk](https://avatars.githubusercontent.com/u/5148394?v=4)](https://github.com/digibeuk "digibeuk (2 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

ipip-adressip-toolsip-utilsiptoolsipv4ipv6networknetworkingphprangesubnetipv6IPnetworkipv4cidrsubnetIP-Tools

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[jalle19/php-whitelist-check

Provides a simple way to check whether an address or domain is on a whitelist

45778.7k4](/packages/jalle19-php-whitelist-check)

PHPackages © 2026

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