Exemplo n.º 1
0
        /// <summary>
        /// Supports managed resources disposal
        /// </summary>
        /// <param name="zoneName"></param>
        /// <returns></returns>

        public virtual DnsRecord[] GetZoneRecords(string zoneName)
        {
            //using (ManagementObjectCollection rrs = wmi.ExecuteQuery(
            //	String.Format("SELECT * FROM MicrosoftDNS_ResourceRecord WHERE DomainName='{0}'", zoneName)))
            //ManagementObjectCollection rrs = GetWmiObjects("MicrosoftDNS_ResourceRecord", "DomainName='{0}'",zoneName);

            ManagementObjectCollection rrsA = wmi.GetWmiObjects("MicrosoftDNS_AType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsAAAA = wmi.GetWmiObjects("MicrosoftDNS_AAAAType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsCNAME = wmi.GetWmiObjects("MicrosoftDNS_CNAMEType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsMX = wmi.GetWmiObjects("MicrosoftDNS_MXType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsNS = wmi.GetWmiObjects("MicrosoftDNS_NSType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsTXT = wmi.GetWmiObjects("MicrosoftDNS_TXTType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsSRV = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='{0}'", zoneName);

            ManagementObjectCollection rrsSRV_tcp = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='_tcp.{0}'", zoneName);

            ManagementObjectCollection rrsSRV_udp = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='_udp.{0}'", zoneName);

            ManagementObjectCollection rrsSRV_tls = wmi.GetWmiObjects("MicrosoftDNS_SRVType", "DomainName='_tls.{0}'", zoneName);

            List <DnsRecord> records = new List <DnsRecord>();
            DnsRecord        record  = new DnsRecord();

            foreach (ManagementObject rr in rrsA)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.A;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = (string)rr.Properties["RecordData"].Value;
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsAAAA)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.AAAA;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = (string)rr.Properties["RecordData"].Value;
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsCNAME)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.CNAME;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = RemoveTrailingDot((string)rr.Properties["RecordData"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsMX)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.MX;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = RemoveTrailingDot((string)rr.Properties["MailExchange"].Value);
                record.MxPriority = Convert.ToInt32(rr.Properties["Preference"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsNS)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.NS;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.RecordData = RemoveTrailingDot((string)rr.Properties["NSHost"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsTXT)
            {
                record            = new DnsRecord();
                record.RecordType = DnsRecordType.TXT;
                record.RecordName = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                string text = (string)rr.Properties["RecordData"].Value;
                record.RecordData = text.Substring(1, text.Length - 2);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV_tcp)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV_udp)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }

            foreach (ManagementObject rr in rrsSRV_tls)
            {
                record             = new DnsRecord();
                record.RecordType  = DnsRecordType.SRV;
                record.RecordName  = CorrectHost(zoneName, (string)rr.Properties["OwnerName"].Value);
                record.SrvPriority = Convert.ToInt32(rr.Properties["Priority"].Value);
                record.SrvWeight   = Convert.ToInt32(rr.Properties["Weight"].Value);
                record.SrvPort     = Convert.ToInt32(rr.Properties["Port"].Value);
                record.RecordData  = RemoveTrailingDot((string)rr.Properties["SRVDomainName"].Value);
                records.Add(record);
            }



            return(records.ToArray());
        }