定制 kai-wang-zone/ip-category 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kai-wang-zone/ip-category

最新稳定版本:v1.0.0

Composer 安装命令:

composer require kai-wang-zone/ip-category

包简介

This is a dependency library for calculating the available IP range

README 文档

README

This is a dependency library for computing available IP ranges, developed based on PHP.

Requirements

PHP >= 5.6

Installation

The recommended method of installing this library is via Composer.

Run the following command from your project root:

composer require kai-wang-zone/ip-category

Usage

1、Initial library loading(Can be ignored in the framework)

<?php
require __DIR__ . "/vendor/autoload.php";

2、IP calculation range

<?php
use \KaiWangZone\ipCategory\IpRangeCalculator;

// 创建计算器实例
$ipCalculator = new IpRangeCalculator();

// 示例1: 计算标准C类网络
$result = $ipCalculator->calculateRange('192.168.1.10', 24);
printIpRangeResult($result);

// 示例2: 计算A类大型网络
$result = $ipCalculator->calculateRange('10.0.0.5', 8);
printIpRangeResult($result);

// 示例3: 计算小范围网络(/30)
$result = $ipCalculator->calculateRange('203.0.113.4', 30);
printIpRangeResult($result);

// 示例4: 计算单个IP(/32)
$result = $ipCalculator->calculateRange('198.51.100.1', 32);
printIpRangeResult($result);

// 示例5: 处理无效输入
try {
    // 无效IP地址
    $ipCalculator->calculateRange('256.168.1.1', 24);
} catch (InvalidArgumentException $e) {
    echo "错误1: " . $e->getMessage() . "<br/>";
}

try {
    // 无效子网掩码
    $ipCalculator->calculateRange('192.168.1.1', 33);
} catch (InvalidArgumentException $e) {
    echo "错误2: " . $e->getMessage() . "<br/>";
}

/**
 * 格式化输出IP范围结果
 */
function printIpRangeResult(array $result)
{
    echo "网络地址: " . $result['network'] . "<br/>";
    echo "广播地址: " . $result['broadcast'] . "<br/>";
    echo "第一个可用IP: " . $result['first_usable'] . "<br/>";
    echo "最后一个可用IP: " . $result['last_usable'] . "<br/>";
    echo "总IP数量: " . number_format($result['total_ips']) . "<br/>";
    echo "可用IP数量: " . number_format($result['usable_ips']) . "<br/>";
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-29