本文介绍了通过C#代码管理DNS服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些示例代码来创建/删除区域,并通过C#创建微软DNS服务器中的A记录

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

推荐答案

使用WMI调用DNSProvider。

You have to use WMI to invoke the DNSProvider.

添加记录:

 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);
}

您可以参考WMI参考,并根据需要使用方法和课程

You can reference the WMI reference and extend this as you need using the methods and classeshttp://msdn.microsoft.com/en-us/library/ms682123(v=vs.85).aspx

这篇关于通过C#代码管理DNS服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 11:14