Query RootDSE using Perl Net-LDAP (Perl)

This code can be found in Chapter 20 of Active Directory Cookbook, 2nd edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

#!/usr/SD/perl/bin/perl
# ---------------------------------------------------------------
# From the book "Active Directory Cookbook" by Robbie Allen
# ISBN: 0-596-00466-4
# ---------------------------------------------------------------

use strict;
use Net::LDAP;

my $ldap_server  = $ARGV[0] || 'dc1';
my $ldapobj = Net::LDAP->new($ldap_server) or die " Could not connect: $@";
my $rootdse = $ldapobj->search(
                    base   => '',
                    filter => '(objectclass=*)',
                    scope  => 'base',
);
die $rootdse->error if $rootdse->code;
foreach $entry($rootdse->entries) {
   foreach $attr(sort $entry->attributes) {
      foreach ($entry->get($attr)) {
         print "$attr: $_\n";
      }
   }
}

This code has been viewed 2837 times.

New from the creators of TechTasks.com: StatSheet.com