且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过 C# 代码管理 DNS 服务器

更新时间:2023-02-07 20:49:55

您必须使用 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 = 
         cmiClass.GetMethodParameters("CreateInstanceFromPropertyData");

     inParams["DnsServerName"] = this.ServerName;
     inParams["ContainerName"] = zone;
     inParams["OwnerName"] = hostName + "." + zone;
     inParams["IPAddress"] = iPAddress;

     cmiClass.InvokeMethod("CreateInstanceFromPropertyData", inParams, null);
}

您可以引用 WMI 引用并根据需要使用方法和类扩展它http://msdn.microsoft.com/en-us/library/ms682123(v=vs.85).aspx

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