Manage DNS server by C# code

£可爱£侵袭症+ 提交于 2019-12-17 18:52:11

问题


I need some sample code to create/delete zone and A record in microsoft DNS server by C#


回答1:


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 = 
         wmiClass.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




回答2:


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



来源:https://stackoverflow.com/questions/5146270/manage-dns-server-by-c-sharp-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!