src/IPUtils.php
public static function getIPRangeBounds($ipRange)
    {
        if (strpos($ipRange, '/') === false) {
            $ipRange = self::sanitizeIpRange($ipRange);

            if ($ipRange === null) {
                return null;
            }
        }
        $pos = strpos($ipRange, '/');

        $bits = substr($ipRange, $pos + 1);
        $range = substr($ipRange, 0, $pos);
        $high = $low = @inet_pton($range);
        if ($low === false) {
            return null;
        }

        $lowLen = strlen($low);
        $i = $lowLen - 1;
        $bits = $lowLen * 8 - $bits;

        for ($n = (int)($bits / 8); $n > 0; $n--, $i--) {
            $low[$i] = chr(0);
            $high[$i] = chr(255);
        }

        $n = $bits % 8;
        if ($n) {
            $low[$i] = chr(ord($low[$i]) & ~((1 << $n) - 1));
            $high[$i] = chr(ord($high[$i]) | ((1 << $n) - 1));
        }

        return array($low, $high);
    }
public static function getIPRangeBounds($ipRange)
    {
        if (strpos($ipRange, '/') === false) {
            $ipRange = self::sanitizeIpRange($ipRange);

            if ($ipRange === null) {
                return null;
            }
        }
        $pos = strpos($ipRange, '/');

        $bits = substr($ipRange, $pos + 1);
        $range = substr($ipRange, 0, $pos);
        $high = $low = @inet_pton($range);
        if ($low === false) {
            return null;
        }

        $lowLen = strlen($low);
        $i = $lowLen - 1;
        $bits = $lowLen * 8 - $bits;

        for ($n = (int)($bits / 8); $n > 0; $n--, $i--) {
            $low[$i] = chr(0);
            $high[$i] = chr(255);
        }

        $n = $bits % 8;
        if ($n) {
            $low[$i] = chr(ord($low[$i]) & ~((1 << $n) - 1));
            $high[$i] = chr(ord($high[$i]) | ((1 << $n) - 1));
        }

        return array($low, $high);
    }
public static function getIPRangeBounds ( $ ipRange ) { if ( strpos ( $ ipRange , '/' ) === false ) { $ ipRange = self :: sanitizeIpRange ( $ ipRange ) ; if ( $ ipRange === null ) { return null ; } } $ pos = strpos ( $ ipRange , '/' ) ; $ bits = substr ( $ ipRange , $ pos + 1 ) ; $ range = substr ( $ ipRange , 0 , $ pos ) ; $ high = $ low = @ inet_pton ( $ range ) ; if ( $ low === false ) { return null ; } $ lowLen = strlen ( $ low ) ; $ i = $ lowLen - 1 ; $ bits = $ lowLen * 8 - $ bits ; for ( $ n = ( int ) ( $ bits / 8 ) ; $ n > 0 ; $ n -- , $ i -- ) { $ low [ $ i ] = chr ( 0 ) ; $ high [ $ i ] = chr ( 255 ) ; } $ n = $ bits % 8 ; if ( $ n ) { $ low [ $ i ] = chr ( ord ( $ low [ $ i ] ) & ~ ( ( 1 << $ n ) - 1 ) ) ; $ high [ $ i ] = chr ( ord ( $ high [ $ i ] ) | ( ( 1 << $ n ) - 1 ) ) ; } return array ( $ low , $ high ) ; }
Get low and high IP addresses for a specified IP range.

@param string $ipRange An IP address range in string format, e.g. `'192.168.1.1/24'`.
@return array|null Array `array($lowIp, $highIp)` in binary format, or null on failure.
Get low and high IP addresses for a specified IP range .