该软件包已被弃用且不再维护。未建议替代软件包。

用于操作CIDR和匹配IP地址的软件包

v1.0.2 2019-12-30 20:06 UTC

This package is auto-updated.

Last update: 2023-06-10 01:54:17 UTC


README

用于操作CIDR和匹配IP地址的软件包。

安装

composer require lorenzoaiello/cidr

示例

<?php

use lorenzoaiello\Cidr\CIDR;

class MyClass
{
    function MyFunction()
    {
        // *** Most Used Functions *** //

        // Compare an IPv4 address with one or more CIDR blocks
        $result = CIDR::matchMulti('10.1.2.3',['172.31.0.0/16', '10.0.0/8']);
        // returns: `true`

        // Compare an IPv4 address with a single CIDR block
        $result = CIDR::match('10.1.2.3','10.0.0/8');
        // returns: `true`

        // Compare an IPv4 address with an exact match
        $result = CIDR::match('10.1.2.3','10.1.2.3');
        // returns: `true`

        // Compare an IPv6 address with a single CIDR block
        $result = CIDR::match('2041:0000:140f::875b:131b','2041:0000:140f:0000:0000:0000:875b:131b/64');
        // returns: `true`

        // *** Wildcards *** //

        CIDR::matchMulti('10.1.2.3',['172.31.*','10.0.0.*']);

        CIDR::match('10.1.2.3','10.0.0.*');
 
        // *** IPv6 Specific ***//
        
        CIDR::IPv6_expand('2041:0000:140f::875b:131b');
        // returns: `2041:0000:140f:0000:0000:0000:875b:131b`
        
        CIDR::IPv6_compress('2041:0000:140F:0000:0000:0000:875B:131B');
        // returns: `2041:0:140f::875b:131b`

    }   
}