| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 /** 11 * class lmbIp. 12 * 13 * @package net 14 * @version $Id: lmbIp.class.php 5945 2007-06-06 08:31:43Z pachanga $ 15 */ 16 class lmbIp 17 { 18 function encodeIpRange($ip_begin, $ip_end) 19 { 20 // Returns ip adressess array with in range $ip_begin - $ip_end 21 if ( !self::isValid($ip_begin) || !self::isValid($ip_end) ) 22 { 23 throw new lmbException("Invalid IP range", array('start' => $ip_begin, 24 'end' => $ip_end)); 25 } 26 $data = array 27 ( 28 lmbIp :: encode($ip_begin), 29 lmbIp :: encode($ip_end) 30 ); 31 $start = hexdec(dechex($data[0])); 32 $end = hexdec(dechex($data[1])); 33 $ip_list = array(); 34 for ( $i=$start; $i<=$end; $i++ ) 35 { 36 if ( ($i & 0x000000FF) == 0x000000FF ) 37 { 38 // Checking for 0.0.0.255 39 continue; 40 }elseif ( ($i & 0x0000FF00) == 0x0000FF00 ) 41 { 42 // Checking for 0.0.255.0 43 $i += 0xFF; 44 continue; 45 }elseif ( ($i & 0x00FF0000) == 0x00FF0000 ) 46 { 47 // Checking for 0.255.0.0 48 $i += 0xFFFF; 49 continue; 50 }elseif ( ($i & 0xFFFFFF) == 0 && $end - $i >= 0xFFFFFF ) 51 { 52 $ip_list[] = $i|0xFFFFFF; 53 $i = hexdec(dechex($i|0xFFFFFF)); 54 }elseif ( ($i & 0xFFFF) == 0 && $end - $i >= 0xFFFF ) 55 { 56 $ip_list[] = $i|0xFFFF; 57 $i = hexdec(dechex($i|0xFFFF)); 58 }elseif ( ($i & 0xFF) == 0 && $end - $i >= 0xFF ) 59 { 60 $ip_list[] = $i|0xFF; 61 $i = hexdec(dechex($i|0xFF)); 62 }else{ 63 $ip_list[] = $i|0; 64 } 65 } 66 return $ip_list; 67 } 68 69 function encode($ip) 70 { 71 // 1.2.3.4 -> 0x01020304 as int 72 return ip2long($ip); 73 } 74 75 function decode($numeric_ip) 76 { 77 // 0x01020304 as int -> 1.2.3.4 78 return long2ip($numeric_ip); 79 } 80 81 function isValid($ip) 82 { 83 return ip2long($ip) !== false; 84 } 85 } 86 87 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Aug 28 04:51:15 2008 | Cross-referenced by PHPXref 0.7 |