Ejemplo n.º 1
0
        /// <summary>
        /// Check whether or not there are MX or Address records associated with the given name.
        /// </summary>
        /// <returns></returns>
        public bool CanMailExchange()
        {
            Results.ResolutionResult lastResult = null;
            using (Iterators.ResolutionIterator iterator = GetIterator(QTYPE.ANY))
            {
                while (iterator.MoveNext())
                {
                    lastResult = iterator.Current;
                }
            }
            if (object.ReferenceEquals(null, lastResult))
            {
                throw new ResolverException("Resolution failed.");
            }
            switch (lastResult.Response.Header.RCODE)
            {
            case RCODE.NoError:
                // check for Address or MX records
                return(lastResult.Response.AnswerRecords.Where(
                           rr => typeof(Address).IsAssignableFrom(rr.GetType()) ||
                           typeof(MX).IsAssignableFrom(rr.GetType())).Any());

            case RCODE.NameError: // Non-existent domain
                return(false);

            default: // failure
                throw new ResolverException(String.Format(
                                                "Unexpected RCODE {0} ({1}) from {2}.",
                                                lastResult.Response.Header.RCODE.ToString(),
                                                lastResult.Response.Header.RCODEValue,
                                                lastResult.Authorities.Selected));
            }
        }
Ejemplo n.º 2
0
        //public Iterators.RequestIterator GetIterator(DnsClient.DNS.QTYPE question)
        //{
        //  return new Iterators.RequestIterator(this, question);
        //}

        public NameServerCollection GetNameServers(out bool isAuthoritative)
        {
            Results.ResolutionResult lastResult = null, lastNonEmptyResult = null;
            using (Iterators.ResolutionIterator iterator = GetIterator(QTYPE.NS))
            {
                while (iterator.MoveNext())
                {
                    lastResult = iterator.Current;
                    if (!lastResult.Authorities.IsEmpty)
                    {
                        lastNonEmptyResult = lastResult;
                    }
                }
            }
            if (object.ReferenceEquals(null, lastResult) ||
                object.ReferenceEquals(null, lastNonEmptyResult))
            {
                throw new ResolverException("Resolution failed.");
            }
            switch (lastResult.Response.Header.RCODE)
            {
            case RCODE.NoError:
                isAuthoritative = lastResult.Response.AnswerRecords.Where(rr => null != rr as NS).Any();
                return(lastNonEmptyResult.Authorities);

            case RCODE.NameError: // Non-existent domain
                isAuthoritative = true;
                return(null);

            default: // failure
                throw new ResolverException(String.Format(
                                                "Unexpected RCODE {0} ({1}) from {2}.",
                                                lastResult.Response.Header.RCODE.ToString(),
                                                lastResult.Response.Header.RCODEValue,
                                                lastResult.Authorities.Selected));
            }
        }