tomcan/subnet-parser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tomcan/subnet-parser

最新稳定版本:1.1.2

Composer 安装命令:

composer require tomcan/subnet-parser

包简介

IP Subnet parser and merger/aggregator

README 文档

README

TomCan's subnet parser and merger library can parse, merge/aggregate IP subnets into a structured Subnet object.

Usage

Add the library to your project using composer

composer require tomcan/subnet-parser

Then just instantiate it

$parser = new TomCan\SubnetParser\SubnetParser();
// Parse ranges into subnets
$subnets = $parser->parseRanges(['192.168.1.0/24', '192.168.2.0/24', '192.168.0.0/24']);
// Merge subnets
$subnets = $parser->mergeSubnets($subnets);
foreach ($subnets as $subnet) {
    echo 'Network: '.$subnet->network.'/'.$subnet->prefixlenght.PHP_EOL;
}

Parsing

This library allows you to parse subnets in various notations. The library will try and figure it out.

192.168.0.1
-> 192.168.0.1/32
192.168.1.1/24
-> 192.168.1.0/24
192.168.2.1/255.255.255.0
-> 192.168.2.0/24
192.168.3.0-192.168.3.255
-> 192.168.3.0/24
192.168.4.0-192.168.5.128
-> 192.168.4.0/24 + 192.168.5.0/25 + 192.168.5.128/32

Merging

It can also merge an array of subnets into the least possible amount of subnets.

192.168.0.0/24
192.168.1.0/24
-> 192.168.0.0/23
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/25
192.168.3.128/25
-> 192.168.0.0/22

The Subnet object

The Subnet object is a very simple but structured object containing the network address and prefix length. It also contains the last IP of the range, as well as the preceding IP (last IP of previous subnet) and the next IP (first IP of the next subnet). IPs are available in their textual representation, as well as in their packed format.

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-11-09