Address = 0; $this->Prefix = 0; } function GetNetMask() { return(0xffffffff ^ ((1 << (32 - $this->Prefix)) - 1)); } function AddressToString() { return(implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255)))); } function AddressFromString($Value) { $Parts = explode('.', $Value); $this->Address = ($Parts[0] << 24) | ($Parts[1] << 16) | ($Parts[2] << 8) | $Parts[3]; } function GetRange() { $From = new NetworkAddressIPv4(); $From->Address = $this->Address; $From->Prefix = 32; $HostMask = 0xffffffff ^ $this->GetNetMask(); $To = new NetworkAddressIPv4(); $To->Address = $From->Address + $HostMask; $To->Prefix = 32; return(array('From' => $From, 'To' => $To)); } function ChangePrefix($NewPrefix) { $this->Prefix = $NewPrefix; if($this->Prefix > 32) $this->Prefix = 32; if($this->Prefix < 0) $this->Prefix = 0; $this->Address = $this->Address & $this->GetNetMask(); } function Contain($Address) { $UpperNetmask = $this->GetNetMask(); if(($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true; else $Result = false; //echo($Address->AddressToString().'/'.$Address->Prefix.' in '.$this->AddressToString().'/'.$this->Prefix.' '.$Result."\n"); return($Result); } } class NetworkAddressIPv6 { var $Address; var $Prefix; function __construct() { $this->Address = 0; $this->Prefix = 0; } function AddressToString() { return(inet_ntop($this->Address)); } function AddressFromString($Value) { $this->Address = inet_pton($Value); } function GetOctets() { $Result = array(); $Data = array_reverse(unpack('C*', $this->Address)); foreach($Data as $Item) { $Result[] = dechex($Item & 15); $Result[] = dechex(($Item >> 4) & 15); } return($Result); } function EncodeMAC($MAC) { $MAC = explode(':', $MAC); $Data = unpack('C*', $this->Address); $Data[9] = hexdec($MAC[0]) ^ 0x02; $Data[10] = hexdec($MAC[1]); $Data[11] = hexdec($MAC[2]); $Data[12] = 0xff; $Data[13] = 0xfe; $Data[14] = hexdec($MAC[3]); $Data[15] = hexdec($MAC[4]); $Data[16] = hexdec($MAC[5]); $this->Address = pack_array('C*', $Data); } }