Create an A and PTR record (Perl)

This code can be found in Chapter 14 of DNS on Windows Server 2003

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.

# Create an A and PTR record

# ---------------------------------------------------------------
# From the book "DNS on Windows Server 2003" 
# By Cricket Liu, Matt Larson & Robbie Allen
# Publisher: O'Reilly and Associates
# ISBN: 0-596-00562-8
# Book web site: http://rallenhome.com/books/dnsonw2k3/toc.html
# ---------------------------------------------------------------

use Win32::OLE;

use strict;

my ($strRR, $strReverseRR, $strDomain, $strReverseDomain);

# A record to add
$strRR = 'matrix.movie.edu. IN A 192.168.64.13';
$strDomain = 'movie.edu';

# PTR record to add
$strReverseRR = '13.64.168.192.in-addr.arpa IN PTR matrix.movie.edu';
$strReverseDomain = '168.192.in-addr.arpa.';

my ($objDNS, $objRR, $objDNSServer, $objRR2, $objOutParam);
$objDNS = Win32::OLE->GetObject('winMgmts:root\\MicrosoftDNS');
$objRR = $objDNS->Get('MicrosoftDNS_ResourceRecord');
$objDNSServer = $objDNS->Get('MicrosoftDNS_Server.Name="."');

# Create the A record
my $strNull;
$strNull = $objRR->CreateInstanceFromTextRepresentation($objDNSServer->Name, $strDomain, $strRR, $objOutParam);

$objRR2 = $objDNS->Get($objOutParam);
print 'Created Record: ' . $objRR2->TextRepresentation, "\n";
$objOutParam = undef;

# Create the PTR record
$strNull = $objRR->CreateInstanceFromTextRepresentation($objDNSServer->Name, $strReverseDomain, $strReverseRR, $objOutParam);

$objRR2 = $objDNS->Get($objOutParam);
print 'Created Record: ' . $objRR2->TextRepresentation, "\n";

This code has been viewed 1617 times.

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