kubrick/lib-ip-tools
Composer 安装命令:
composer require kubrick/lib-ip-tools
包简介
Various IPv4 ans IPv6 Tools
README 文档
README
Various IPv4 and IPv6 tools for PHP
Getting Started
Installation
lib-ip-tools requires PHP >= 8.2.
composer require kubrick/lib-ip-tools
1. IPv4
IPv4 address
include 'vendor/autoload.php'; // Create an IPv4 address $ipv4 = new \Kubrick\IpTools\IP\IPv4('10.0.0.1', 24);
Available attributes are:
->ipBinaryreturn the string equivalent binary ip address eg: 00001010000000000000000000000000->ipAddressreturn the ip address eg: 10.0.0.1->networkMaskreturn the network mask eg: 24->hostMaskreturn the host mask eg: 8->binaryNetworkPartreturn the network part as string equivalent eg: 000010100000000000000000->binaryHostPartreturn the host part as string equivalent eg: 00000001
IPv4 Subnet calculator
You can also
include 'vendor/autoload.php'; // Will return the next 5 addresses (.2 .3 .4 .5 .6) $addresses = \Kubrick\IpTools\IP\IPv4SubnetCalculator::nextAddresses( new \Kubrick\IpTools\IP\IPv4('10.0.0.1', 24), 5 ); // Will return ip addresses between .2 and .49 (given ip address are excluded) $addresses = \Kubrick\IpTools\IP\IPv4SubnetCalculator::missingAddresses( [ new \Kubrick\IpTools\IP\IPv4('10.0.0.1', 24), new \Kubrick\IpTools\IP\IPv4('10.0.0.10', 24), new \Kubrick\IpTools\IP\IPv4('10.0.0.50', 24) ] );
2. IPv6
IPv6 Address
include 'vendor/autoload.php'; // Create an IPv6 address $ipv6 = new \Kubrick\IpTools\IP\IPv6('2001::1', 64);
Available attributes are:
->ipBinaryreturn the string equivalent binary ip address eg: 00100000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001->ipAddressreturn the ip address eg: 2001:0000:0000:0000:0000:0000:0000:0001->ipAddressAbvreturn the ip address on abbreviate format eg: 2001::1->networkMaskreturn the network mask eg: 64->hostMaskreturn the host mask eg: 64->binaryNetworkPartreturn the network part as string equivalent eg: 0010000000000001000000000000000000000000000000000000000000000000->binaryHostPartreturn the host part as string equivalent eg: 0000000000000000000000000000000000000000000000000000000000000001
IPv6 Subnet calculator
require 'vendor/autoload.php'; // Like ipv4 this will return the 5 new addresses $addresses = \Kubrick\IpTools\IP\IPv6SubnetCalculator::nextAddresses( new \Kubrick\IpTools\IP\IPv6('2001::', 64), 5 ); // This will return the 5 next IPv6 prefixes, you need to pass the ISP prefix eg. 48 and the number of prefixes you want $addresses = \Kubrick\IpTools\IP\IPv6SubnetCalculator::nextPrefixes( new \Kubrick\IpTools\IP\IPv6('2001::', 56), 48, 5 ); // like ipv4 this will return missing ipv6 addresses $addresses = \Kubrick\IpTools\IP\IPv6SubnetCalculator::missingAddresses( [ new \Kubrick\IpTools\IP\IPv6('2001::', 64), new \Kubrick\IpTools\IP\IPv6('2001::5', 64), new \Kubrick\IpTools\IP\IPv6('2001::f', 64) ] ); // like ipv4 this will return the missings prefixes, you juste have to provive the ISP prefix. $addresses = \Kubrick\IpTools\IP\IPv6SubnetCalculator::missingPrefixes( [ new \Kubrick\IpTools\IP\IPv6('2001:0:0:0000::', 56), new \Kubrick\IpTools\IP\IPv6('2001:0:0:0300::', 56) ], 48 );
3. Mac address
include 'vendor/autoload.php'; //create a mac address $mac = new \Kubrick\IpTools\MAC\MacAddress('00:11:22:33:44:55'); // get the short format (001122334455) echo $mac->toShort(); // get the long format (00:11:22:33:44:55) echo $mac->toLong(); // you can also increment or decrement mac address (00:11:22:33:44:5a) $mac->increment(5)->toLong()
Available methods are:
toShort():stringreturn the short format of the mac address eg. 001122334455toLong():stringreturn the long format of the mac address eg. 00:11:22:33:44:55getOUI():stringreturn the OUI eg. 001122getNIC():stringreturn the NIC eg. 334455incrementBy(int):selfincrement mac address by the number givendecrementBy(int):selfdecrement mac address by the number given
4. DHCPv6 DUID
require 'vendor/autoload.php'; $duid = new \Kubrick\IpTools\DUID\DUID('000423b6290dcb1b7113059a2247a7b12f05'); // getIdentifier() method will automatically display the good value, macAddress, uuid or identifier echo $duid->getIdentifier(); // you can olso display other informations // display DUID mac value if type LLT or LL echo $duid->macAddress; // display the pen number in case of DUID-EN type echo $duid->pen;
Available attributes are:
->duidreturns the DUID without ":"->typereturns the type of DUID->linkreturns the link type->macAddressreturns the mac address->penreturns the iana pen number->identifierreturns the identifier->timestampreturns the unix epoch timestamp->uuidreturns the uuid
Available methods are:
getIdentifier()returns the identifier base on duid type (eg mac address for LL & LLT, ...)
Available static methods are:
::createDUIDLLT()create a LLT DUID Type::createDUIDLL()create a LL DUID type::createDUIDEN()create an EN DUID type
kubrick/lib-ip-tools 适用场景与选型建议
kubrick/lib-ip-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「network」 「IP」 「ipv4」 「MAC」 「duid」 「ipv6NA」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kubrick/lib-ip-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kubrick/lib-ip-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kubrick/lib-ip-tools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A stand-alone class implementation of the IPv4+IPv6 IP+CIDR aggregator from CIDRAM.
OAuth 2.0 server for Yii 2.0 with MAC tokens support.
Stuff validator
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
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: WTFPL
- 更新时间: 2025-10-03