littledevnl/iptools
Composer 安装命令:
composer require littledevnl/iptools
包简介
Small package for handling things with IPs and networks
README 文档
README
This package is a set of tools for working with IP addresses and networks.
A lot of the internals are inspired by S1lentium/IPTools, but when using that package I noticed I started by wrapping everything I needed in separate classes. Which lead me to create my own package.
The state is pretty alpha at this point but feel free to use it. I do my best to not change the interfaces and facades if possible.
Installation
composer require littledevnl/iptools
Getting started
use Littledev\IPTools\Address; use Littledev\IPTools\Network; use Littledev\IPTools\Iterator\AddressIterator; use Littledev\IPTools\Family\IPFamily; $ip = Address::parse($_SERVER['REMOTE_ADDR']); if ($ip->family() === IPFamily::v6()) { echo 'Good for you!'; } $network6 = Network::parse('2001:db8::/64'); if ($network6->contains($ip)) { echo 'You use an IP which is reserved for documentation.'; } $localNetwork = Network::parse('127.0.0.1/24'); if ($localNetwork->contains($ip)) { echo 'No place like localhost.'; } $iterator = new AddressIterator($localNetwork); foreach ($iterator as $address) { echo 'In local network: ' . $address->address(); }
Goals
- No dependencies.
- A set of tools for parsing and working with IP addresses and networks
- Utility classes should be open for extension through a common parent
Changelog
- [v0.1] Parsing of IP addresses and networks.
- [v0.2]
constainsnow accepts networks and addresses. Generalized - [v0.3] Network Iterators
- [v0.4] Network lists
- [v1.0] Reworked interfaces
- [v1.1] Fixed composer PHP requirement, supports PHP7.4 and up
- [v1.2] Fix for shorter inAddr inputs
Limitations
Not yet a complete set of tools, it is just the beginning.
Without external dependencies for things like arbitrary precision numbers, it is impossible to do certain things. For instance calculating the number of hosts in a IPV6 network. You can do it yourself with bcmath, see the example below
use Littledev\IPTools\Network; use Littledev\IPTools\Family\IPFamily; $net = Network::parse('2001:db8::/64'); $numbersOfAddresses = bcpow('2', (string)(IPFamily::v6()->maxPrefix() - $net->subnet()->prefix()));
littledevnl/iptools 适用场景与选型建议
littledevnl/iptools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 691 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 littledevnl/iptools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 littledevnl/iptools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 691
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-18