Back to the module list

IP addresses calculation

The IP addresses in IPv4 and IPv6 are complex to manage. In cause, the differents allowed formats.

The module allow to uncompress an IPv6 address (::1 is converted to 0000:0000:0000:0000:0000:0000:0000:0001), reverse an IP address (to use in DNS server in Reverse zones), calculate a CIDR associated to a IPv4 netmask

The class definition

Class \ipaddresses

Namespace \

Description

 Manage the IP addresses conversions

Properties

No property available

Methods

public function cidrToBin ($cidr, $length)
 Return the provided CIDR in binary. Length must be in bytes.
 Return FALSE if the parameters are invalid
 @param integer $cidr The CIDR to convert
 @param integer $length The length to use

public function completeAddressWithZero ($ip)
 Return the IP adddress with filling the fields with the missing zeros.
 Valid only on IPv6 (but don't change anything if the provided address is
 IPv4)
 @param string $ip The IP to complete

public function groupIPv6 ($ipv6)
 Get an IPv6 address with the format
 x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x
 and return it with format
 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
 Return false if the IP provided is not complete
 @param string $ipv6 The IPv6 to group

public function netmask2cidr ($netmask)
 This function return the CIDR associated to the provided netmask
 Ex. Return 24 for a mask 255.255.255.0
 Work only in IPv4
 Return FALSE if the provided IP is invalid
 @param string $netmask The mask to convert in CIDR

public function reverseIPAddress ($ipReverse)
 Reverse the provided IP address
 The IPv6 are returned in format :
 x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x
 @param string $ipReverse The IPv6 to reverse

public function str_base_convert ($str, $frombase=10, $tobase=36)
 Base conversion with 128 bits support for IPv6
 Based on http://fr2.php.net/manual/en/function.base-convert.php#109660
 @param string $str The string to convert
 @param integer|null $frombase The base of the provided string (10 by
 default)
 @param integer|null $tobase The base of the returned string (36 by
 default)

public function uncompressIPv6 ($ip)
 Return the IPv6 uncompressed (all the fields exists). They are not filled
 by zeros
 If the provided IP is IPv4, there is no change applied
 Return False if the parameter is invalid
 Based on http://www.weberdev.com/get_example.php3?ExampleID=3921
 @param string $ip The IP address to uncompress

public function validIPAddress ($ip)
 Return true if the provided IP address is valid (IPv4 or IPv6)
 @param string $ip The IP Address to validate

public function validIPv4Address ($ip)
 Return true if the provided IP address is valid and is IPv4
 @param string $ip The IP Address to validate

public function validIPv6Address ($ip)
 Return true if the provided IP address is valid and is IPv6
 @param string $ip The IP Address to validate