PHPackages                             cse/helpers-ip - 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. [Framework](/categories/framework)
4. /
5. cse/helpers-ip

ActiveLibrary[Framework](/categories/framework)

cse/helpers-ip
==============

The helpers allows you to manipulating network IP addresses (IPv4 and IPv6).

1.0.4(7y ago)717921MITPHPPHP &gt;=7.1

Since Feb 18Pushed 7y ago3 watchersCompare

[ Source](https://github.com/cs-eliseev/helpers-ip)[ Packagist](https://packagist.org/packages/cse/helpers-ip)[ Docs](https://github.com/cs-eliseev/helpers-ip)[ RSS](/packages/cse-helpers-ip/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (6)Used By (1)

English | [Русский](https://github.com/cs-eliseev/helpers-ip/blob/master/README.ru_RU.md)

IP CSE HELPERS
==============

[](#ip-cse-helpers)

[![Travis (.org)](https://camo.githubusercontent.com/67b975839cd59950b2e65a41e927d68d2a8d4dff36b2c7e81e966e33b250dc95/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f63732d656c69736565762f68656c706572732d69702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/cs-eliseev/helpers-ip)[![Codecov](https://camo.githubusercontent.com/9ab14842afa365dc6b6db851009e8f4525cd384a211c63157ddf45e2de6f00b7/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f63732d656c69736565762f68656c706572732d69702e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/cs-eliseev/helpers-ip)[![Scrutinizer code quality](https://camo.githubusercontent.com/36f8d3574b543cfa0118e90dfcf7205e0e62bb1ed5ea4c22943ce9dcf9efd348/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f63732d656c69736565762f68656c706572732d69702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cs-eliseev/helpers-ip/?branch=master)

[![Packagist](https://camo.githubusercontent.com/7a8f4803ade32da20a1f432f0a4565dcc6d012d22d2ae1ff66571c564addaf06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6373652f68656c706572732d69702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cse/helpers-ip)[![Minimum PHP Version](https://camo.githubusercontent.com/dcd4b4aec2c1709157fa6a2c050f709d75cde9552a79cfff0b70a97fad7281ae/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cse/helpers-ip)[![Packagist](https://camo.githubusercontent.com/633ed03ee4a21088ea282380e0e74727443567bdfb0db845dd6835f910971d3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6373652f68656c706572732d69702e7376673f7374796c653d666c61742d737175617265)](https://github.com/cs-eliseev/helpers-ip/blob/master/LICENSE.md)[![GitHub repo size](https://camo.githubusercontent.com/e3ce0d4fff66140423e0fafddc144cb280f2ad2a1b21ef1d5543e6bd66b46b4c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f63732d656c69736565762f68656c706572732d69702e7376673f7374796c653d666c61742d737175617265)](https://github.com/cs-eliseev/helpers-ip/archive/master.zip)

The helpers allows you to manipulating network IP addresses (IPv4 and IPv6).

Project repository:

**DEMO**

```
$ip = IP::getRealIP();
if (IP::isIP($ip)) {
    switch (true) {
        case IP::isIPv4($ip):
            break;
        case IP::isIPv6($ip):
            $ip = IP::removeSubnetMaskIPv6($ip);
            $ip = IP::getRangeIPv6($ip);
            $ip = IP::getFirstIPByVersion($ip);
            break;
    }
    $version = IP::getVersionIP($ip);
}
```

---

Introduction
------------

[](#introduction)

[CSE HELPERS](https://github.com/cs-eliseev/helpers/blob/master/README.md) is a collection of several libraries with simple functions written in PHP for people.

Despite using PHP as the main programming language for the Internet, its functions are not enough. IP CSE HELPERS for manipulating network IP addresses (IPv4 and IPv6).

[CSE HELPERS](https://github.com/cs-eliseev/helpers/blob/master/README.md) was created for the rapid development of web applications.

**CSE Helpers project:**

- [Array CSE helpers](https://github.com/cs-eliseev/helpers-arrays)
- [Cookie CSE helpers](https://github.com/cs-eliseev/helpers-cookie)
- [Date CSE helpers](https://github.com/cs-eliseev/helpers-date)
- [Email CSE helpers](https://github.com/cs-eliseev/helpers-email)
- [IP CSE helpers](https://github.com/cs-eliseev/helpers-ip)
- [Json CSE helpers](https://github.com/cs-eliseev/helpers-json)
- [Math Converter CSE helpers](https://github.com/cs-eliseev/helpers-math-converter)
- [Phone CSE helpers](https://github.com/cs-eliseev/helpers-phone)
- [Request CSE helpers](https://github.com/cs-eliseev/helpers-request)
- [Session CSE helpers](https://github.com/cs-eliseev/helpers-session)
- [Word CSE helpers](https://github.com/cs-eliseev/helpers-word)

Below you will find some information on how to init library and perform common commands.

Install
-------

[](#install)

You can find the most recent version of this project [here](https://github.com/cs-eliseev/helpers-ip).

### Composer

[](#composer)

Execute the following command to get the latest version of the package:

```
composer require cse/helpers-ip
```

Or file composer.json should include the following contents:

```
{
    "require": {
        "cse/helpers-ip": "*"
    }
}
```

### Git

[](#git)

Clone this repository locally:

```
git clone https://github.com/cs-eliseev/helpers-ip.git
```

### Download

[](#download)

[Download the latest release here](https://github.com/cs-eliseev/helpers-ip/archive/master.zip).

Usage
-----

[](#usage)

The class consists of static methods that are conveniently used in any project. See example [examples-ip.php](https://github.com/cs-eliseev/helpers-ip/blob/master/examples/examples-ip.php).

**Get real IP address**

Example:

```
IP::getRealIP();
// xxx.xxx.xxx.xxx
```

**Remove subnet mask IPv6**

Example:

```
IP::removeSubnetMaskIPv6('2a0a:2b40::4:60/124');
// 2a0a:2b40::4:60
```

**Check is IPv4 address**

Example:

```
IP::isIPv4('127.0.0.1');
// true
```

Check is IPv6:

```
IP::isIPv4('2a0a:2b40::4:60');
// false
```

Check is not IP:

```
IP::isIPv4('256.256.256');
// false
```

**Check is IPv6 address**

Example:

```
IP::isIPv6('2a0a:2b40::4:60');
// true
```

Check null:

```
IP::isIPv6('::');
// true
```

Check localhost IPv6:

```
IP::isIPv6('::1');
// true
IP::isIPv6('0:0:0:0:0:0:0:1');
// true
```

Check is IPv4:

```
IP::isIPv6('127.0.0.1');
// false
```

Check is not IP:

```
IP::isIPv6(':');
// false
```

**Get version IP address**

Example:

```
IP::getVersionIP('::1');
// 6
```

Get versin IPv4:

```
IP::getVersionIP('127.0.0.1');
// 4
```

Get versin IPv6:

```
IP::getVersionIP('0:0:0:0:0:0:0:1');
// 6
```

Get versin in not IP:

```
IP::getVersionIP('256.256.256.256');
// null
```

**Is IP address**

Example:

```
IP::isIP('::1');
// true
```

Check versin IPv4:

```
IP::isIP('127.0.0.1');
// true
```

Check versin IPv6:

```
IP::isIP('0:0:0:0:0:0:0:1');
// true
```

Check versin in not IP:

```
IP::isIP('256.256.256.256');
// false
```

**Get range IPv6 address**

Example:

```
IP::getRangeIPv6('2a0a:2b40::4:60/124');
// ['2a0a:2b40::4:60', '2a0a:2b40::4:6f']
```

**Filter IPs address**

Example:

```
IP::filterIPs([
    '127.0.0.1',
    '2a0a:2b40::4:60',
    '255.255.255.255',
    '2a0a:2b40::4:6f',
    '256.256.256.256'
]);
// [4 => ['127.0.0.1', '255.255.255.255'], 6 => ['2a0a:2b40::4:60', '2a0a:2b40::4:6f']]
```

Not data IP version:

```
IP::filterIPs([
    '127.0.0.1',
    '255.255.255.255',
    '256.256.256.256'
]);
// [4 => ['127.0.0.1', '255.255.255.255'], 6 => []]
```

Filter IPv4 address:

```
IP::filterIPs([
    '127.0.0.1',
    '2a0a:2b40::4:60',
    '255.255.255.255',
    '2a0a:2b40::4:6f',
    '256.256.256.256'
], 4);
// ['127.0.0.1', '255.255.255.255']
```

Filter IPv6 address:

```
IP::filterIPs([
    '127.0.0.1',
    '2a0a:2b40::4:60',
    '255.255.255.255',
    '2a0a:2b40::4:6f',
    '256.256.256.256'
], 6);
// ['2a0a:2b40::4:60', '2a0a:2b40::4:6f']
```

**Get first IP by version**

Example:

```
IP::getFirstIPByVersion([
    '256.256.256.256',
    '127.0.0.1',
    '2a0a:2b40::4:60',
    '255.255.255.255',
    '2a0a:2b40::4:6f',
    '256.256.256.256'
], 4);
// '127.0.0.1'
```

Get first IP by version 6:

```
IP::getFirstIPByVersion([
    '256.256.256.256',
    '127.0.0.1',
    '2a0a:2b40::4:60',
    '255.255.255.255',
    '2a0a:2b40::4:6f'
], 6);
// '2a0a:2b40::4:60'
```

Testing &amp; Code Coverage
---------------------------

[](#testing--code-coverage)

PHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.

General PHPUnit documentation can be found at .

To run the PHPUnit unit tests, execute:

```
phpunit PATH/TO/PROJECT/tests/
```

If you want code coverage reports, use the following:

```
phpunit --coverage-html ./report PATH/TO/PROJECT/tests/
```

Used PHPUnit default config:

```
phpunit --configuration PATH/TO/PROJECT/phpunit.xml
```

Donating
--------

[](#donating)

You can support this project [here](https://www.paypal.me/cseliseev/10usd). You can also help out by contributing to the project, or reporting bugs. Even voicing your suggestions for features is great. Anything to help is much appreciated.

License
-------

[](#license)

The IP CSE HELPERS is open-source PHP library licensed under the MIT license. Please see [License File](https://github.com/cs-eliseev/helpers-ip/blob/master/LICENSE.md) for more information.

---

> GitHub [@cs-eliseev](https://github.com/cs-eliseev)

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

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

Total

5

Last Release

2620d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3b9e49d0ce3fd71c8eb31b7c14e48373dbb415a9d16950ce52d23bf89b2ae26?d=identicon)[ak\_eliseev](/maintainers/ak_eliseev)

---

Top Contributors

[![cs-eliseev](https://avatars.githubusercontent.com/u/24221291?v=4)](https://github.com/cs-eliseev "cs-eliseev (72 commits)")

---

Tags

collectioncollectionscseframeworkhelperhelpersipipsips4ipv4ipv6librarynetworknetworkingphptooltoolsutilitiesutilityutilsframeworkipv6libraryIPbasicnetworkprojectipv4csecs-eliseev

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cse-helpers-ip/health.svg)

```
[![Health](https://phpackages.com/badges/cse-helpers-ip/health.svg)](https://phpackages.com/packages/cse-helpers-ip)
```

###  Alternatives

[mlocati/ip-lib

Handle IPv4, IPv6 addresses and ranges

3126.4M44](/packages/mlocati-ip-lib)[s1lentium/iptools

PHP Library for manipulating network addresses (IPv4 and IPv6)

2446.2M24](/packages/s1lentium-iptools)[cse/helpers-session

The helpers allows you to easily manage session data. START, SET, GET DELETE, HAS method session - all this is available in this library.

102.6k3](/packages/cse-helpers-session)

PHPackages © 2026

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