par
gigelgigel » 03 août 2006, 17:40
[quote="Ripat"]Trouvé ceci dans le cache de Google:
[php]function imask($this){
return base_convert((pow(2,32) - pow(2, (32-$this))), 10, 16);
}
function imaxblock($ibase, $tbit){
while ($tbit > 0){
$im = hexdec(imask($tbit-1));
$imand = $ibase & $im;
if ($imand != $ibase) {
break;
}
$tbit--;
}
return $tbit;
}
function ip2cidr ($istart, $iend) {
$s = explode(".", $istart);
$start = "";
$dot = "";
while (list($key, $val) = each($s)) {
$start = sprintf("%s%s%d", $start, $dot, $val);
$dot = ".";
}
$end = "";
$dot = "";
$e = explode(".", $iend);
while (list($key,$val) = each($e)) {
$end = sprintf("%s%s%d", $end, $dot, $val);
$dot = ".";
}
$start = ip2long($start);
$end = ip2long($end);
$result = array();
while ($end > $start) {
$maxsize = imaxblock($start,32);
$x = log($end - $start + 1)/log(2);
$maxdiff = floor(32 - floor($x));
$ip = long2ip($start);
if ($maxsize < $maxdiff){
$maxsize = $maxdiff;
}
array_push($result, "$ip/$maxsize");
$start += pow(2, (32-$maxsize));
}
return $result;
}
$a = ip2cidr('192.168.0.158' , '192.168.0.255');
echo '<pre>'; print_r ($a); echo '</pre>';
[/php]
Je n'en suis pas l'auteur, donc ne me pose pas trop de questions!
http://66.249.93.104/search?q=cache:yDH ... =clnk&cd=1[/quote]
Hmmm, je l'ai essayé pour qq intervalles et je pense qu'il fait ce dont j'ai besoin. Merci bien