gwk/ip_address
Composer 安装命令:
composer require gwk/ip_address
包简介
IP address handling library
README 文档
README
This library allows you to handle IP addresses in various forms (currently IPv4 only) and test whether an IP matches certain constraints (equality, in a subnet or in a range).
Example
<?php use IPAddress\IPv4\Address; use IPAddress\IPv4\Subnet; $address = new Address("1.2.8.200"); // These statements yield the same address $address = new Address(0x010208c8); $address = new Address(array(1, 2, 8, 200)); $address = new Address(array("1", "2", "010", "0xc8")); $subnet = new Subnet("1.2.3.4", "255.255.0.0"); // These statements yield the same subnet $subnet = Subnet::fromCidr("1.2.3.4", 16); $subnet = Subnet::fromString("1.2.3.4 255.255.0.0"); $subnet = Subnet::fromString("1.2.3.4/16"); if($address->isPrivate()) { echo "Your address is in one of the RFC1918 Private networks.\n"; } if($subnet->match($address)) { echo "I know your address is in the \"$subnet\" subnet.\n"; // OUTPUT: I know your address is in the "1.2.3.4 netmask 255.255.0.0" subnet. }
The library's test have been run on both 32-bit and 64-bit php and should work on both. Please note that the Address class' int() method (which returns the integer representation of an IP address) will return a negative number for ip addresses larger than 127.255.255.255 on 32-bit php due to the fact that php doesn't support unsigned integers.
TODO
- More utility methods
- IPv6 support
Disclaimer
I have limited knowledge of IP addresses so I could have made some mistakes regarding terminology or even behavior of the library in certain cases.
License
MIT, see LICENSE
gwk/ip_address 适用场景与选型建议
gwk/ip_address 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.94k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2013 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「network」 「utility」 「IP」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gwk/ip_address 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gwk/ip_address 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gwk/ip_address 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
A collection of enhancements and utilities for the Silverstripe UserForms module
Extends TYPO3 EXT:seo hreflang functionality
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
PHP7 utility classes
PHP SDK for Bands In Town API
统计信息
- 总下载量: 11.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-04-17