Listing09_Create_Subnet (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 $new_subnet = '10.4.2.0/24';
my $subnet_site = 'RTP';

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

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

my $ldap = Net::LDAP->new($server) or die "$@";
my $result = $ldap->bind($user, password => $passwd);
$result->code && die $result->error;
s
print "Creating subnet $new_subnet\n";
$result = $ldap->add (
             dn   => "cn=$new_subnet,cn=Subnets,$sites_dn",
             attr => [ objectclass => 'subnet',
                       siteObject  => "cn=$subnet_site,$sites_dn",
                     ]);
$result->code && die $result->error;
print "Subnet creation complete\n";
$ldap->unbind;

This code has been viewed 579 times.

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