All pastes #949940 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-20 05:08 UTC
rendered paste body
<?php
$CIDR = $_GET['IP'];

        /* get the base and the bits from the ban in the database */
        list($base, $bits) = explode('/', $CIDR);

        /* now split it up into it's classes */
        list($a, $b, $c, $d) = explode('.', $base);

        /* now do some bit shfiting/switching to convert to ints */
        $i = ($a << 24) + ($b << 16) + ($c << 8) + $d;
        $mask = $bits == 0 ? 0 : (~0 << (32 - $bits));

        /* here's our lowest int */
        $low = $i & $mask;

        /* here's our highest int */
        $high = $i | (~$mask & 0xFFFFFFFF);

echo long2ip($high);
echo "-";
echo long2ip($low);
?>