{"id":22747164,"url":"https://github.com/cs-eliseev/helpers-ip","last_synced_at":"2025-04-14T11:33:46.292Z","repository":{"id":56959781,"uuid":"170965447","full_name":"cs-eliseev/helpers-ip","owner":"cs-eliseev","description":"The helpers allows you to manipulating network IP addresses (IPv4 and IPv6).","archived":false,"fork":false,"pushed_at":"2019-04-27T07:25:09.000Z","size":59,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T00:44:49.608Z","etag":null,"topics":["collection","collections","cse","framework","helper","helpers","ip","ips","ips4","ipv4","ipv6","library","network","networking","php","tool","tools","utilities","utility","utils"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cs-eliseev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-16T05:12:48.000Z","updated_at":"2022-10-01T18:06:23.000Z","dependencies_parsed_at":"2022-08-21T05:10:23.554Z","dependency_job_id":null,"html_url":"https://github.com/cs-eliseev/helpers-ip","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-ip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-ip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-ip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cs-eliseev%2Fhelpers-ip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cs-eliseev","download_url":"https://codeload.github.com/cs-eliseev/helpers-ip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248872179,"owners_count":21175361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collection","collections","cse","framework","helper","helpers","ip","ips","ips4","ipv4","ipv6","library","network","networking","php","tool","tools","utilities","utility","utils"],"created_at":"2024-12-11T03:13:30.190Z","updated_at":"2025-04-14T11:33:45.854Z","avatar_url":"https://github.com/cs-eliseev.png","language":"PHP","funding_links":["https://www.paypal.me/cseliseev/10usd"],"categories":[],"sub_categories":[],"readme":"English | [Русский](https://github.com/cs-eliseev/helpers-ip/blob/master/README.ru_RU.md)\n\nIP CSE HELPERS\n=======\n\n[![Travis (.org)](https://img.shields.io/travis/cs-eliseev/helpers-ip.svg?style=flat-square)](https://travis-ci.org/cs-eliseev/helpers-ip)\n[![Codecov](https://img.shields.io/codecov/c/github/cs-eliseev/helpers-ip.svg?style=flat-square)](https://codecov.io/gh/cs-eliseev/helpers-ip)\n[![Scrutinizer code quality](https://img.shields.io/scrutinizer/g/cs-eliseev/helpers-ip.svg?style=flat-square)](https://scrutinizer-ci.com/g/cs-eliseev/helpers-ip/?branch=master)\n\n[![Packagist](https://img.shields.io/packagist/v/cse/helpers-ip.svg?style=flat-square)](https://packagist.org/packages/cse/helpers-ip)\n[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg?style=flat-square)](https://packagist.org/packages/cse/helpers-ip)\n[![Packagist](https://img.shields.io/packagist/l/cse/helpers-ip.svg?style=flat-square)](https://github.com/cs-eliseev/helpers-ip/blob/master/LICENSE.md)\n[![GitHub repo size](https://img.shields.io/github/repo-size/cs-eliseev/helpers-ip.svg?style=flat-square)](https://github.com/cs-eliseev/helpers-ip/archive/master.zip)\n\nThe helpers allows you to manipulating network IP addresses (IPv4 and IPv6).\n\nProject repository: https://github.com/cs-eliseev/helpers-ip\n\n**DEMO**\n```php\n$ip = IP::getRealIP();\nif (IP::isIP($ip)) {\n    switch (true) {\n        case IP::isIPv4($ip):\n            break;\n        case IP::isIPv6($ip):\n            $ip = IP::removeSubnetMaskIPv6($ip);\n            $ip = IP::getRangeIPv6($ip);\n            $ip = IP::getFirstIPByVersion($ip);\n            break;\n    }\n    $version = IP::getVersionIP($ip);\n}\n```\n\n***\n\n## Introduction\n\n[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.\n\nDespite 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).\n\n[CSE HELPERS](https://github.com/cs-eliseev/helpers/blob/master/README.md) was created for the rapid development of web applications.\n\n**CSE Helpers project:**\n* [Array CSE helpers](https://github.com/cs-eliseev/helpers-arrays)\n* [Cookie CSE helpers](https://github.com/cs-eliseev/helpers-cookie)\n* [Date CSE helpers](https://github.com/cs-eliseev/helpers-date)\n* [Email CSE helpers](https://github.com/cs-eliseev/helpers-email)\n* [IP CSE helpers](https://github.com/cs-eliseev/helpers-ip)\n* [Json CSE helpers](https://github.com/cs-eliseev/helpers-json)\n* [Math Converter CSE helpers](https://github.com/cs-eliseev/helpers-math-converter)\n* [Phone CSE helpers](https://github.com/cs-eliseev/helpers-phone)\n* [Request CSE helpers](https://github.com/cs-eliseev/helpers-request)\n* [Session CSE helpers](https://github.com/cs-eliseev/helpers-session)\n* [Word CSE helpers](https://github.com/cs-eliseev/helpers-word)\n\nBelow you will find some information on how to init library and perform common commands.\n\n## Install\n\nYou can find the most recent version of this project [here](https://github.com/cs-eliseev/helpers-ip).\n\n### Composer\n\nExecute the following command to get the latest version of the package:\n```bash\ncomposer require cse/helpers-ip\n```\n\nOr file composer.json should include the following contents:\n```json\n{\n    \"require\": {\n        \"cse/helpers-ip\": \"*\"\n    }\n}\n```\n\n### Git\n\nClone this repository locally:\n```bash\ngit clone https://github.com/cs-eliseev/helpers-ip.git\n```\n\n### Download\n\n[Download the latest release here](https://github.com/cs-eliseev/helpers-ip/archive/master.zip).\n\n## Usage\n\nThe 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).\n\n**Get real IP address**\n\nExample:\n```php\nIP::getRealIP();\n// xxx.xxx.xxx.xxx\n```\n\n**Remove subnet mask IPv6**\n\nExample:\n```php\nIP::removeSubnetMaskIPv6('2a0a:2b40::4:60/124');\n// 2a0a:2b40::4:60\n```\n\n**Check is IPv4 address**\n\nExample:\n```php\nIP::isIPv4('127.0.0.1');\n// true\n```\n\nCheck is IPv6:\n```php\nIP::isIPv4('2a0a:2b40::4:60');\n// false\n```\n\nCheck is not IP:\n```php\nIP::isIPv4('256.256.256');\n// false\n```\n\n**Check is IPv6 address**\n\nExample:\n```php\nIP::isIPv6('2a0a:2b40::4:60');\n// true\n```\n\nCheck null:\n```php\nIP::isIPv6('::');\n// true\n```\n\nCheck localhost IPv6:\n```php\nIP::isIPv6('::1');\n// true\nIP::isIPv6('0:0:0:0:0:0:0:1');\n// true\n```\n\nCheck is IPv4:\n```php\nIP::isIPv6('127.0.0.1');\n// false\n```\n\nCheck is not IP:\n```php\nIP::isIPv6(':');\n// false\n```\n\n**Get version IP address**\n\nExample:\n```php\nIP::getVersionIP('::1');\n// 6\n```\n\nGet versin IPv4:\n```php\nIP::getVersionIP('127.0.0.1');\n// 4\n```\n\nGet versin IPv6:\n```php\nIP::getVersionIP('0:0:0:0:0:0:0:1');\n// 6\n```\n\nGet versin in not IP:\n```php\nIP::getVersionIP('256.256.256.256');\n// null\n```\n\n**Is IP address**\n\nExample:\n```php\nIP::isIP('::1');\n// true\n```\n\nCheck versin IPv4:\n```php\nIP::isIP('127.0.0.1');\n// true\n```\n\nCheck versin IPv6:\n```php\nIP::isIP('0:0:0:0:0:0:0:1');\n// true\n```\n\nCheck versin in not IP:\n```php\nIP::isIP('256.256.256.256');\n// false\n```\n\n**Get range IPv6 address**\n\nExample:\n```php\nIP::getRangeIPv6('2a0a:2b40::4:60/124');\n// ['2a0a:2b40::4:60', '2a0a:2b40::4:6f']\n```\n\n**Filter IPs address**\n\nExample:\n```php\nIP::filterIPs([\n    '127.0.0.1',\n    '2a0a:2b40::4:60',\n    '255.255.255.255',\n    '2a0a:2b40::4:6f',\n    '256.256.256.256'\n]);\n// [4 =\u003e ['127.0.0.1', '255.255.255.255'], 6 =\u003e ['2a0a:2b40::4:60', '2a0a:2b40::4:6f']]\n```\n\nNot data IP version:\n```php\nIP::filterIPs([\n    '127.0.0.1',\n    '255.255.255.255',\n    '256.256.256.256'\n]);\n// [4 =\u003e ['127.0.0.1', '255.255.255.255'], 6 =\u003e []]\n```\n\nFilter IPv4 address:\n```php\nIP::filterIPs([\n    '127.0.0.1',\n    '2a0a:2b40::4:60',\n    '255.255.255.255',\n    '2a0a:2b40::4:6f',\n    '256.256.256.256'\n], 4);\n// ['127.0.0.1', '255.255.255.255']\n```\n\nFilter IPv6 address:\n```php\nIP::filterIPs([\n    '127.0.0.1',\n    '2a0a:2b40::4:60',\n    '255.255.255.255',\n    '2a0a:2b40::4:6f',\n    '256.256.256.256'\n], 6);\n// ['2a0a:2b40::4:60', '2a0a:2b40::4:6f']\n```\n\n**Get first IP by version**\n\nExample:\n```php\nIP::getFirstIPByVersion([\n    '256.256.256.256',\n    '127.0.0.1',\n    '2a0a:2b40::4:60',\n    '255.255.255.255',\n    '2a0a:2b40::4:6f',\n    '256.256.256.256'\n], 4);\n// '127.0.0.1'\n```\n\nGet first IP by version 6:\n```php\nIP::getFirstIPByVersion([\n    '256.256.256.256',\n    '127.0.0.1',\n    '2a0a:2b40::4:60',\n    '255.255.255.255',\n    '2a0a:2b40::4:6f'\n], 6);\n// '2a0a:2b40::4:60'\n```\n\n\n## Testing \u0026 Code Coverage\n\nPHPUnit is used for unit testing. Unit tests ensure that class and methods does exactly what it is meant to do.\n\nGeneral PHPUnit documentation can be found at https://phpunit.de/documentation.html.\n\nTo run the PHPUnit unit tests, execute:\n```bash\nphpunit PATH/TO/PROJECT/tests/\n```\n\nIf you want code coverage reports, use the following:\n```bash\nphpunit --coverage-html ./report PATH/TO/PROJECT/tests/\n```\n\nUsed PHPUnit default config:\n```bash\nphpunit --configuration PATH/TO/PROJECT/phpunit.xml\n```\n\n\n## Donating\n\nYou can support this project [here](https://www.paypal.me/cseliseev/10usd). \nYou can also help out by contributing to the project, or reporting bugs. \nEven voicing your suggestions for features is great. Anything to help is much appreciated.\n\n\n## License\n\nThe 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.\n\n***\n\n\u003e GitHub [@cs-eliseev](https://github.com/cs-eliseev)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs-eliseev%2Fhelpers-ip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcs-eliseev%2Fhelpers-ip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcs-eliseev%2Fhelpers-ip/lists"}