I need some sample code to create/delete zone and A record in microsoft DNS server by C#
After you set up a DNS server, you can manage the DNS server from the DNS management console. From this management console, you can perform common administrative tasks, such as adding additional zones, changing zone settings, adding A or MX records to an existing zone, and so on.
Click “Configure Address Records” next to each entry and verify that the IP address is the same as your cPanel server. This will add the necessary records to the zone file. Finally, tell your registrar about the DNS server’s domain names. The process differs depending on the registrar, so you should consult their DNS server documentation or
The domain name system is a hierarchical arrangement of servers that fall into two broad categories: recursive and authoritative. The one that knows the mapping between a site’s domain name and IP address is its authoritative DNS server; it’s the definitive source of truth about that domain.
The DNS WMI Provider enables the administration of DNS Servers from the server itself, or from remote hosts. The general steps necessary to administer a DNS Server using the DNS WMI Provider are: Listing or modifying a server property, or using a method
You have to use WMI to invoke the DNSProvider.
This to add a record:
public void AddARecord(string hostName, string zone, string iPAddress, string dnsServerName)
{
ManagementScope scope =
new ManagementScope(@"\\" + dnsServerName + "\\root\\MicrosoftDNS");
scope.Connect();
ManagementClass cmiClass =
new ManagementClass(scope,
new ManagementPath("MicrosoftDNS_AType"),
null);
ManagementBaseObject inParams =
cmiClass.GetMethodParameters("CreateInstanceFromPropertyData");
inParams["DnsServerName"] = this.ServerName;
inParams["ContainerName"] = zone;
inParams["OwnerName"] = hostName + "." + zone;
inParams["IPAddress"] = iPAddress;
cmiClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null);
}
You can reference the WMI reference and extend this as you need using the methods and classes http://msdn.microsoft.com/en-us/library/ms682123(v=vs.85).aspx
Microsoft exposes it as a POX service, so you could just push XML over the wire to it, using the System.Net stuff & your user credentials.
http://technet.microsoft.com/en-us/library/dd278634.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With