我编写了一个项目来管理 Dns。我可以为创建和删除区域、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);
}
}