cse/helpers-ip
Composer 安装命令:
composer require cse/helpers-ip
包简介
The helpers allows you to manipulating network IP addresses (IPv4 and IPv6).
README 文档
README
English | Русский
IP CSE HELPERS
The helpers allows you to manipulating network IP addresses (IPv4 and IPv6).
Project repository: https://github.com/cs-eliseev/helpers-ip
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
CSE HELPERS 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 was created for the rapid development of web applications.
CSE Helpers project:
- Array CSE helpers
- Cookie CSE helpers
- Date CSE helpers
- Email CSE helpers
- IP CSE helpers
- Json CSE helpers
- Math Converter CSE helpers
- Phone CSE helpers
- Request CSE helpers
- Session CSE helpers
- Word CSE helpers
Below you will find some information on how to init library and perform common commands.
Install
You can find the most recent version of this project here.
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
Clone this repository locally:
git clone https://github.com/cs-eliseev/helpers-ip.git
Download
Download the latest release here.
Usage
The class consists of static methods that are conveniently used in any project. See example 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 & 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 https://phpunit.de/documentation.html.
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
You can support this project here. 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
The IP CSE HELPERS is open-source PHP library licensed under the MIT license. Please see License File for more information.
GitHub @cs-eliseev
cse/helpers-ip 适用场景与选型建议
cse/helpers-ip 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 179 次下载、GitHub Stars 达 5, 最近一次更新时间为 2019 年 02 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「network」 「ipv6」 「library」 「project」 「basic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cse/helpers-ip 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cse/helpers-ip 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cse/helpers-ip 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A stand-alone class implementation of the IPv4+IPv6 IP+CIDR aggregator from CIDRAM.
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
PHP Library for manipulating network addresses (IPv4 and IPv6)
Manages IPv4 and IPv6 addresses and subnets
Official PHP SDK for the IPGeolocation.io IP Location API with single and bulk lookup support.
统计信息
- 总下载量: 179
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-18