DNS Server

  • Thread starter Thread starter Leigh
  • Start date Start date
L

Leigh

Hi,
Is it possible to interface with the DNS Server to create and delete
records? I trying to create a utility that will create (A) Host records
automatically. Any information, help or examples would be greatly received.

Regards, Leigh
 
yes. One way is to use a tool like nsupdate.exe and start that in a
process and get the return codes. To do it with code, I would use WMI. Has
all the methods for createzone, add rrs, (etc.), and you can do it with with
the system.management classes. Get and use the WMITools on the ms site, and
the dnsprov.dll in the w2k resource kit or on the ftp site. The wmitools
really help figure out what methods are in each class and how to call them
and what they return, etc. If you just need to create A records, I could
send you an example in c# if you like.
 
William,
I would really appreciate it if you would send me an example. please send
to leigh DOT pointer AT subzero-solutions DOT net

Thank you, Leigh
 
Leigh,

It is considered bad Netiquette to request that answers be sent to your
personal email address.

Many newsgroup "posters" do not respond to these kinds of requests. Why
"hog" the answer all for yourself? Maybe some of us would like to see the
answer as well.
 
Sure:
public void CreateRR(string zoneName, string rrTextRep)
{
if ( zoneName == null )
throw new ArgumentNullException("zoneName", "zoneName is null.");
if ( rrTextRep == null )
throw new ArgumentNullException("rrTextRep", "rrTextRep is null.");

InvokeMethodOptions options = new InvokeMethodOptions();
options.Timeout = new TimeSpan(0,0,0,5);

ManagementClass rrClass = new ManagementClass(
ms,
new ManagementPath("MicrosoftDNS_ResourceRecord"),
null);

//Get an input parameters object for this method
ManagementBaseObject inParams =
rrClass.GetMethodParameters("CreateInstanceFromTextRepresentation");

//Fill in input parameter values
//inParams["DnsServerName"] = null; //Don't need.
inParams["ContainerName"] = zoneName;
inParams["TextRepresentation"] = rrTextRep;

//Execute the method
try
{
ManagementBaseObject outObject = rrClass.InvokeMethod
("CreateInstanceFromTextRepresentation", inParams, null);
PropertyDataCollection outProperties = outObject.Properties;
foreach (PropertyData outProperty in outProperties)
{
Console.WriteLine("Property = " + outProperty.Name);
}
}
catch
{
throw new ApplicationException("CreateInstanceFromTextRepresentation
method failed.");
}
} // End CreateInstanceFromTextRepresentation Method.

--
William Stacey, DNS MVP

Leigh said:
William,
I would really appreciate it if you would send me an example. please send
to leigh DOT pointer AT subzero-solutions DOT net

Thank you, Leigh
....
 
Scott I understand butif you like.
I assumed William was going to send an example project or class file.

Leigh
 
Cool, thanks

William Stacey said:
Sure:
public void CreateRR(string zoneName, string rrTextRep)
{
if ( zoneName == null )
throw new ArgumentNullException("zoneName", "zoneName is null.");
if ( rrTextRep == null )
throw new ArgumentNullException("rrTextRep", "rrTextRep is null.");

InvokeMethodOptions options = new InvokeMethodOptions();
options.Timeout = new TimeSpan(0,0,0,5);

ManagementClass rrClass = new ManagementClass(
ms,
new ManagementPath("MicrosoftDNS_ResourceRecord"),
null);

//Get an input parameters object for this method
ManagementBaseObject inParams =
rrClass.GetMethodParameters("CreateInstanceFromTextRepresentation");

//Fill in input parameter values
//inParams["DnsServerName"] = null; //Don't need.
inParams["ContainerName"] = zoneName;
inParams["TextRepresentation"] = rrTextRep;

//Execute the method
try
{
ManagementBaseObject outObject = rrClass.InvokeMethod
("CreateInstanceFromTextRepresentation", inParams, null);
PropertyDataCollection outProperties = outObject.Properties;
foreach (PropertyData outProperty in outProperties)
{
Console.WriteLine("Property = " + outProperty.Name);
}
}
catch
{
throw new ApplicationException("CreateInstanceFromTextRepresentation
method failed.");
}
} // End CreateInstanceFromTextRepresentation Method.

--
William Stacey, DNS MVP

Leigh said:
William,
I would really appreciate it if you would send me an example. please send
to leigh DOT pointer AT subzero-solutions DOT net

Thank you, Leigh
...
 
Back
Top