Esempio n. 1
0
        public static IEnumerable <DNSRecord> Get_DomainDNSRecord(Args_Get_DomainDNSRecord args = null)
        {
            if (args == null)
            {
                args = new Args_Get_DomainDNSRecord();
            }

            var SearcherArguments = new Args_Get_DomainSearcher
            {
                LDAPFilter       = @"(objectClass=dnsNode)",
                SearchBasePrefix = $@"DC={args.ZoneName},CN=MicrosoftDNS,DC=DomainDnsZones",
                Domain           = args.Domain,
                Server           = args.Server,
                Properties       = args.Properties,
                ResultPageSize   = args.ResultPageSize,
                ServerTimeLimit  = args.ServerTimeLimit,
                Credential       = args.Credential
            };
            var DNSSearcher = GetDomainSearcher.Get_DomainSearcher(SearcherArguments);

            SearchResult[]   Results = null;
            List <DNSRecord> Outs    = null;

            if (DNSSearcher != null)
            {
                if (args.FindOne)
                {
                    Results = new SearchResult[] { DNSSearcher.FindOne() };
                }
                else
                {
                    var items = DNSSearcher.FindAll();
                    if (items != null)
                    {
                        Results = new SearchResult[items.Count];
                        items.CopyTo(Results, 0);
                    }
                }
                if (Results != null)
                {
                    foreach (var result in Results)
                    {
                        DNSRecord Out = null;
                        try
                        {
                            var ldapProperty = ConvertLDAPProperty.Convert_LDAPProperty(result.Properties);
                            Out = new DNSRecord
                            {
                                name = ldapProperty.name,
                                distinguishedname = ldapProperty.distinguishedname,
                                dnsrecord         = ldapProperty.dnsrecord,
                                whencreated       = ldapProperty.whencreated,
                                whenchanged       = ldapProperty.whenchanged,
                                ZoneName          = args.ZoneName
                            };

                            // convert the record and extract the properties
                            DNSRecord Record = null;
                            if (Out.dnsrecord is System.DirectoryServices.ResultPropertyValueCollection)
                            {
                                // TODO: handle multiple nested records properly?
                                Record = Convert_DNSRecord((Out.dnsrecord as System.DirectoryServices.ResultPropertyValueCollection)[0] as byte[]);
                            }
                            else
                            {
                                Record = Convert_DNSRecord(Out.dnsrecord as byte[]);
                            }

                            if (Record != null)
                            {
                                if (Record.RecordType != null)
                                {
                                    Out.RecordType = Record.RecordType;
                                }
                                else if (Record.UpdatedAtSerial != null)
                                {
                                    Out.UpdatedAtSerial = Record.UpdatedAtSerial;
                                }
                                else if (Record.TTL != null)
                                {
                                    Out.TTL = Record.TTL;
                                }
                                else if (Record.Age != null)
                                {
                                    Out.Age = Record.Age;
                                }
                                else if (Record.TimeStamp != null)
                                {
                                    Out.TimeStamp = Record.TimeStamp;
                                }
                                else if (Record.Data.IsNotNullOrEmpty())
                                {
                                    Out.Data = Record.Data;
                                }
                                else if (Record.ZoneName.IsNotNullOrEmpty())
                                {
                                    Out.ZoneName = Record.ZoneName;
                                }
                                else if (Record.name.IsNotNullOrEmpty())
                                {
                                    Out.name = Record.name;
                                }
                                else if (Record.distinguishedname.IsNotNullOrEmpty())
                                {
                                    Out.distinguishedname = Record.distinguishedname;
                                }
                                else if (Record.dnsrecord != null)
                                {
                                    Out.dnsrecord = Record.dnsrecord;
                                }
                                else if (Record.whencreated != null)
                                {
                                    Out.whencreated = Record.whencreated;
                                }
                                else if (Record.whenchanged != null)
                                {
                                    Out.whenchanged = Record.whenchanged;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Logger.Write_Warning($@"[Get-DomainDNSRecord] Error: {e}");
                        }
                        if (Outs == null)
                        {
                            Outs = new List <DNSRecord>();
                        }
                        Outs.Add(Out);
                    }
                }
                DNSSearcher.Dispose();
            }
            return(Outs);
        }
Esempio n. 2
0
 public static IEnumerable <DNSRecord> Get_DNSRecord(Args_Get_DomainDNSRecord args = null)
 {
     return(GetDomainDNSRecord.Get_DomainDNSRecord(args));
 }