承接 tomcan/subnet-parser 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tomcan/subnet-parser

最新稳定版本:1.3.0

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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固