public static function LDAPNetAddr($networkaddress)
	{
		$addr = "";
		$addrtype = (int) substr($networkaddress, 0, 1);

		// Throw away bytes 0 and 1 which should be the addrtype and the "#" separator
		$networkaddress = substr($networkaddress, 2);

		if (($addrtype == 8) || ($addrtype = 9))
		{
			// TODO 1.6: If UDP or TCP, (TODO fill addrport and) strip portnumber information from address
			$networkaddress = substr($networkaddress, (strlen($networkaddress) - 4));
		}

		$addrtypes = array(
			'IPX',
			'IP',
			'SDLC',
			'Token Ring',
			'OSI',
			'AppleTalk',
			'NetBEUI',
			'Socket',
			'UDP',
			'TCP',
			'UDP6',
			'TCP6',
			'Reserved (12)',
			'URL',
			'Count');
		$len = strlen($networkaddress);

		if ($len > 0)
		{
			for ($i = 0; $i < $len; $i++)
			{
				$byte = substr($networkaddress, $i, 1);
				$addr .= ord($byte);

				if (($addrtype == 1) || ($addrtype == 8) || ($addrtype = 9))
				{
					// Dot separate IP addresses...
					$addr .= ".";
				}
			}

			if (($addrtype == 1) || ($addrtype == 8) || ($addrtype = 9))
			{
				// Strip last period from end of $addr
				$addr = substr($addr, 0, strlen($addr) - 1);
			}
		}
		else
		{
			$addr .= 'Address not available.';
		}

		return array('protocol' => $addrtypes[$addrtype], 'address' => $addr);
	}
public static function LDAPNetAddr($networkaddress)
	{
		$addr = "";
		$addrtype = (int) substr($networkaddress, 0, 1);

		// Throw away bytes 0 and 1 which should be the addrtype and the "#" separator
		$networkaddress = substr($networkaddress, 2);

		if (($addrtype == 8) || ($addrtype = 9))
		{
			// TODO 1.6: If UDP or TCP, (TODO fill addrport and) strip portnumber information from address
			$networkaddress = substr($networkaddress, (strlen($networkaddress) - 4));
		}

		$addrtypes = array(
			'IPX',
			'IP',
			'SDLC',
			'Token Ring',
			'OSI',
			'AppleTalk',
			'NetBEUI',
			'Socket',
			'UDP',
			'TCP',
			'UDP6',
			'TCP6',
			'Reserved (12)',
			'URL',
			'Count');
		$len = strlen($networkaddress);

		if ($len > 0)
		{
			for ($i = 0; $i < $len; $i++)
			{
				$byte = substr($networkaddress, $i, 1);
				$addr .= ord($byte);

				if (($addrtype == 1) || ($addrtype == 8) || ($addrtype = 9))
				{
					// Dot separate IP addresses...
					$addr .= ".";
				}
			}

			if (($addrtype == 1) || ($addrtype == 8) || ($addrtype = 9))
			{
				// Strip last period from end of $addr
				$addr = substr($addr, 0, strlen($addr) - 1);
			}
		}
		else
		{
			$addr .= 'Address not available.';
		}

		return array('protocol' => $addrtypes[$addrtype], 'address' => $addr);
	}
public static function LDAPNetAddr ( $ networkaddress ) { $ addr = "" ; $ addrtype = ( int ) substr ( $ networkaddress , 0 , 1 ) ; // Throw away bytes 0 and 1 which should be the addrtype and the "#" separator $ networkaddress = substr ( $ networkaddress , 2 ) ; if ( ( $ addrtype == 8 ) || ( $ addrtype = 9 ) ) { // TODO 1.6: If UDP or TCP, (TODO fill addrport and) strip portnumber information from address $ networkaddress = substr ( $ networkaddress , ( strlen ( $ networkaddress ) - 4 ) ) ; } $ addrtypes = array ( 'IPX' , 'IP' , 'SDLC' , 'Token Ring' , 'OSI' , 'AppleTalk' , 'NetBEUI' , 'Socket' , 'UDP' , 'TCP' , 'UDP6' , 'TCP6' , 'Reserved (12)' , 'URL' , 'Count' ) ; $ len = strlen ( $ networkaddress ) ; if ( $ len > 0 ) { for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ byte = substr ( $ networkaddress , $ i , 1 ) ; $ addr .= ord ( $ byte ) ; if ( ( $ addrtype == 1 ) || ( $ addrtype == 8 ) || ( $ addrtype = 9 ) ) { // Dot separate IP addresses... $ addr .= "." ; } } if ( ( $ addrtype == 1 ) || ( $ addrtype == 8 ) || ( $ addrtype = 9 ) ) { // Strip last period from end of $addr $ addr = substr ( $ addr , 0 , strlen ( $ addr ) - 1 ) ; } } else { $ addr .= 'Address not available.' ; } return array ( 'protocol' => $ addrtypes [ $ addrtype ] , 'address' => $ addr ) ; }
Extract readable network address from the LDAP encoded networkAddress attribute.

Please keep this document block and author attribution in place.

Novell Docs, see: http://developer.novell.com/ndk/doc/ndslib/schm_enu/data/sdk5624.html#sdk5624
for Address types: http://developer.novell.com/ndk/doc/ndslib/index.html?page=/ndk/doc/ndslib/schm_enu/data/sdk4170.html
LDAP Format, String:
taggedData = uint32String "#" octetstring
byte 0 = uint32String = Address Type: 0= IPX Address; 1 = IP Address
byte 1 = char = "#" - separator
byte 2+ = octetstring - the ordinal value of the address
Note: with eDirectory 8.6.2, the IP address (type 1) returns
correctly, however, an IPX address does not seem to.  eDir 8.7 may correct this.
Enhancement made by Merijn van de Schoot:
If addresstype is 8 (UDP) or 9 (TCP) do some additional parsing like still returning the IP address

@param   string  $networkaddress  The network address

@return  array

@author  Jay Burrell, Systems & Networks, Mississippi State University
@since   1.0
Extract readable network address from the LDAP encoded networkAddress attribute .