Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00015 final class IpUtils extends StaticFactory
00016 {
00017 public static function makeRanges(array $ips)
00018 {
00019 $ipsAsIntegers = array();
00020
00021 foreach ($ips as $ip)
00022 $ipsAsIntegers[] = ip2long($ip);
00023
00024 sort($ipsAsIntegers);
00025
00026 $size = count($ipsAsIntegers);
00027
00028 $ranges = array();
00029
00030 $j = 0;
00031
00032 $ranges[$j][] = long2ip($ipsAsIntegers[0]);
00033
00034 for ($i = 1; $i < $size; ++$i) {
00035 if ($ipsAsIntegers[$i] != $ipsAsIntegers[$i - 1] + 1) {
00036 $ranges[++$j][] = long2ip($ipsAsIntegers[$i]);
00037 } else
00038 $ranges[$j][] = long2ip($ipsAsIntegers[$i]);
00039 }
00040
00041 return $ranges;
00042 }
00043 }
00044 ?>