Exemplo n.º 1
0
        public DnsReplyCode GetMXRecords(string domain, out MX_Record[] mxRecords)
        {
            mxRecords = null;

            ArrayList answers = QueryServer(domain, QTYPE.MX, 1).Answers;

            if (answers != null)
            {
                SortedList mx            = new SortedList();
                ArrayList  duplicateList = new ArrayList();
                foreach (object answer in answers)
                {
                    if (answer is MX_Record)
                    {
                        MX_Record mxRec = (MX_Record)answer;

                        if (!mx.Contains(mxRec.Preference))
                        {
                            mx.Add(mxRec.Preference, mxRec);
                        }
                        else
                        {
                            duplicateList.Add(mxRec);
                        }
                    }
                }

                mxRecords = new MX_Record[mx.Count + duplicateList.Count];
                mx.Values.CopyTo(mxRecords, 0);
                duplicateList.CopyTo(mxRecords, mx.Count);
            }

            if (mxRecords == null || mxRecords.Length == 0)
            {
                return(DnsReplyCode.NoEntries);
            }

            return(DnsReplyCode.Ok);
        }
        /// <summary>
        /// Gets MX records.(MX records are sorted by preference, lower array element is prefered)
        /// </summary>
        /// <returns></returns>
        public MX_Record[] GetMXRecords()
        {
            MX_Record[] mxRecords     = (MX_Record[])FilterRecords(m_pAnswers, typeof(MX_Record)).ToArray(typeof(MX_Record));
            SortedList  mx            = new SortedList();
            ArrayList   duplicateList = new ArrayList();

            foreach (MX_Record mxRecord in mxRecords)
            {
                if (!mx.Contains(mxRecord.Preference))
                {
                    mx.Add(mxRecord.Preference, mxRecord);
                }
                else
                {
                    duplicateList.Add(mxRecord);
                }
            }

            mxRecords = new MX_Record[mx.Count + duplicateList.Count];
            mx.Values.CopyTo(mxRecords, 0);
            duplicateList.CopyTo(mxRecords, mx.Count);

            return(mxRecords);
        }