Listing15_Links_For_Site (Perl)

This code can be found in Chapter 9 of Managing Enterprise Active Directory Services

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.

# From the book "Managing Enterprise Active Directory Services"
# ISBN: 0-672-32125-4

use strict;
use Net::LDAP;

my $query_site = 'RTP';

my $server  = 'dc1.xyz.com';
my $user    = 'administrator@xyz.com';
my $passwd  = 'password';

# This could be dynamically retrieved using RootDSE
my $sites_dn = "cn=sites,cn=configuration,dc=xyz,dc=com";
my $ist_dn   = "cn=Inter-Site Transports,$sites_dn";

my $ldap = Net::LDAP->new($server) or die "$@";
my $result = $ldap->bind($user, password => $passwd);
$result->code && die $result->error;

my $filter = "(&(objectclass=siteLink)(objectcategory=SiteLink)";
   $filter .= "(siteList=cn=$query_site,$sites_dn))";
$result = $ldap->search(base   => $ist_dn,
                        scope  => "subtree",
                        attrs  => [ 'cn', 'cost' ],
                        filter => $filter);
$result->code && die $result->error;
my $count = 0;
foreach my $entry ($result->entries) {
   $count++;
   my $name = $entry->get_value('cn');
   my $cost = $entry->get_value('cost');
   print "$count. $name ($cost)\n";
}
$ldap->unbind;

This code has been viewed 587 times.

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