我无法得到所有Dns Zone的ARecords

时间:2012-08-23 06:12:11

标签: c# dns

我编写了一个项目来管理Dns。我可以编写创建和删除Zone,NsRecord和ARecord的代码,但我无法获得区域的ARecords。 谁能指导我?

这是我的代码示例:

private void CreateZone(string domainName)
{
    wmiScope = new ManagementScope("\\\\" + System.Environment.MachineName + "\\ROOT\\MicrosoftDNs");
    wmiScope.Connect();
    var zonePath = new ManagementPath("MicrosoftDNs_Zone");
    var zone = new ManagementClass(wmiScope, zonePath, null);
    var inParams = zone.GetMethodParameters("CreateZone");

    inParams.Properties["ZoneName"].Value = domainName;
    inParams.Properties["ZoneType"].Value = 0;

    zone.InvokeMethod("CreateZone", inParams, null);

    var query = new ObjectQuery("SELECT * FROM MicrosoftDNs_SOAType WHERE OwnerName = '" + domainName + "'");
    var searcher = new ManagementObjectSearcher(wmiScope, query);
    var zoneRecordes = searcher.Get();

    foreach (ManagementObject zoneRecorde in zoneRecordes)
    {
        var soaParams = zoneRecorde.GetMethodParameters("Modify");
        soaParams.Properties["PrimaryServer"].Value = "ns1.domain.com";
        soaParams.Properties["ResponsibleParty"].Value = "contact@domain.com";
        zoneRecorde.InvokeMethod("Modify", soaParams, null);
    }
}

1 个答案:

答案 0 :(得分:1)

为了完成,我将添加让我们得到解决方案的答案。

根据以下网站(discuss.fogcreek.com/dotnetquestions/…),您应该可以获得这样的ARecords:

ManagementScope oMs = new ManagementScope("\\\\" + dnsServer + "\\root\\microsoftdns"); 
string strQuery = "select * from microsoftdns_" + recType + "type where containername = '" + domain + "'"; 
ManagementObjectSearcher oS = new ManagementObjectSearcher(strQuery); oS.Scope = oMs; 
ManagementObjectCollection oRc = oS.Get();