tiat/libs-ip
Composer 安装命令:
composer require tiat/libs-ip
包简介
MIT-licensed PHP 8.5+ IPv4/IPv6 address, CIDR and classification utilities.
README 文档
README
MIT-licensed PHP 8.5+ IPv4/IPv6 address, CIDR and classification utilities.
This package provides:
- strict IPv4 parsing (rejects
127.1, octal, leading zeros, hex, decimal-long) - full IPv6 parsing with
::compression, embedded IPv4 and zone-id handling - canonical RFC 5952 IPv6 formatting (lowercase, longest-zero-run compression)
- IANA special-purpose classification (
isPublic/isPrivate/isLoopback/ ...) - IPv4-mapped IPv6 (
::ffff:a.b.c.d) classified by the embedded IPv4 — SSRF-safe - CIDR blocks: network, broadcast, size, membership
- inclusive, order-agnostic range membership
- comparison and ordering (IPv4 sorts before IPv6)
- no-throw
tryParseAPIs for request, cache and routing paths - dependency-free: no GMP, no BCMath, no BigInt polyfill
Install
composer require tiat/libs-ip:^1.0
Representation
Addresses are held in their big-endian binary form: 4 bytes for IPv4, 16 bytes for IPv6. All comparison, range and CIDR maths runs on those bytes, so results are exact and family-uniform.
64-bit contract
IPv6 is a 128-bit family. This library performs IPv6 maths on the 16-byte binary
form and requires a 64-bit runtime (PHP_INT_SIZE >= 8). On a 32-bit runtime,
every IPv6 entry point fails fast with Tiat\Libs\Ip\UnsupportedPlatformException
rather than silently producing wrong results. IPv4 continues to work on a 32-bit
runtime.
Usage
use Tiat\Libs\Ip\Ip;
use Tiat\Libs\Ip\Cidr;
use Tiat\Libs\Ip\IpUtil;
Ip::parse('2001:db8::1')->toString(); // "2001:db8::1"
IpUtil::isPublic('::ffff:127.0.0.1'); // false (loopback)
IpUtil::isValid('127.1'); // false (strict)
Cidr::parse('10.0.0.0/8')->contains(Ip::parse('10.1.2.3')); // true
IpUtil::within('10.0.0.5', '10.0.0.1', '10.0.0.10'); // true
Versioning
The package starts at 1.0.0 and follows semantic versioning.
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-21