Changeset 698 for trunk/Common/NetworkAddress.php
- Timestamp:
- Sep 28, 2014, 10:41:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/NetworkAddress.php
r695 r698 5 5 var $Address; 6 6 var $Prefix; 7 7 8 8 function __construct() 9 9 { … … 11 11 $this->Prefix = 0; 12 12 } 13 13 14 14 function GetNetMask() 15 15 { … … 21 21 return(implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255)))); 22 22 } 23 23 24 24 function AddressFromString($Value) 25 25 { … … 27 27 $this->Address = ($Parts[0] << 24) | ($Parts[1] << 16) | ($Parts[2] << 8) | $Parts[3]; 28 28 } 29 29 30 30 function GetRange() 31 31 { … … 37 37 $To->Address = $From->Address + $HostMask; 38 38 $To->Prefix = 32; 39 return(array('From' => $From, 'To' => $To)); 39 return(array('From' => $From, 'To' => $To)); 40 40 } 41 41 … … 49 49 50 50 function Contain($Address) 51 { 51 { 52 52 $UpperNetmask = $this->GetNetMask(); 53 53 if(($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true; … … 62 62 var $Address; 63 63 var $Prefix; 64 64 65 65 function __construct() 66 66 { … … 68 68 $this->Prefix = 0; 69 69 } 70 70 71 71 function AddressToString() 72 72 { 73 73 return(inet_ntop($this->Address)); 74 74 } 75 75 76 76 function AddressFromString($Value) 77 77 { 78 78 $this->Address = inet_pton($Value); 79 79 } 80 80 81 function GetOctets() 82 { 83 $Result = array(); 84 $Data = array_reverse(unpack('C*', $this->Address)); 85 foreach($Data as $Item) 86 { 87 88 $Result[] = dechex($Item & 15); 89 $Result[] = dechex(($Item >> 4) & 15); 90 } 91 return($Result); 92 } 93 81 94 }
Note:
See TracChangeset
for help on using the changeset viewer.