通过 C# 代码管理 DNS 服务器 [英] Manage DNS server by C# code

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

问题描述

我需要一些示例代码来通过 C# 在 Microsoft 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 = 
         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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆