Reading the Network Address from LDAP

Novell Cool Solutions: Tip

Digg This - Slashdot This

Posted: 6 May 2004

If you have run more than a few LDAP queries in your day, you may have noticed that the eDirectory Network Address field looks a bit strange. There's a reason for that - the value is actually returned in base 64, which is not the easiest stuff to read. TID 10087142 talks about this issue, and the discussion below sheds more light on the subject.


As the TID mentions, Novell Support has a PERL script available to convert the address into a readable form. Here is a PHP example from one of our readers that does the same thing:

$addy =$info[$i]["networkaddress"][$j];
$bit = 0;
$theip = "";
for ( $k = 2; $k < 6; $k++ ) {
      $theip = $theip.($bit ? "." : "") . ord(substr($addy, $k, 1));
      $bit = 1;
print $theip;

You can also do it the long way. LDAP uses the SYN_NET_ADDRESS syntax to map DS attribute values into LDAP. The line that LDAP returns for the IP address looks like this:

networkAddress:: MSNaBAQE

When you decode the base 64, you get something like this (spaces added to make it more readable):

31 23 5A 04 04 04

Hex 31 is "1", hex 23 is "#", and so on.

In SYN_NET_ADDRESS, "1" means its an IP address; "#" is used by LDAP to delimit fields of different data types; the rest of the string (5A 04 04 04) is the IP address: ...

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© Micro Focus