Ejemplo n.º 1
0
 /// <summary>
 /// Begin send a query to a domain name server to perform a
 /// lookup on the specified domian and return the records.
 /// </summary>
 /// <param name="domain">The domain to get records for.</param>
 /// <param name="dnsType">The dns record type to return.</param>
 /// <param name="dnsClass">The class to search in.</param>
 /// <param name="callback">The asynchronous call back method.</param>
 /// <param name="state">The state object value.</param>
 /// <returns>The asynchronous result.</returns>
 public virtual IAsyncResult BeginQuery(string domain, Nequeo.Net.Dns.DnsType dnsType,
                                        Nequeo.Net.Dns.DnsClass dnsClass, AsyncCallback callback, object state)
 {
     // Return an AsyncResult.
     return(new AsyncDnsQueryRequest(domain, dnsType,
                                     dnsClass, this, callback, state));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Construct the question from parameters, checking for safety
        /// </summary>
        /// <param name="domain">the domain name to query eg. bigdevelopments.co.uk</param>
        /// <param name="dnsType">the QTYPE of query eg. DnsType.MX</param>
        /// <param name="dnsClass">the CLASS of query, invariably DnsClass.IN</param>
        internal Question(string domain, Nequeo.Net.Dns.DnsType dnsType,
                          Nequeo.Net.Dns.DnsClass dnsClass)
        {
            // check the input parameters
            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }

            // do a sanity check on the domain name to make sure its legal
            if (domain.Length == 0 || domain.Length > 255 || !Regex.IsMatch(domain, @"^[a-z|A-Z|0-9|-|_]{1,63}(\.[a-z|A-Z|0-9|-|_]{1,63})+$"))
            {
                // domain names can't be bigger tan 255 chars, and individal labels can't be bigger than 63 chars
                throw new ArgumentException("The supplied domain name was not in the correct form", "domain");
            }

            // sanity check the DnsType parameter
            if (!Enum.IsDefined(typeof(Nequeo.Net.Dns.DnsType), dnsType) || dnsType == Nequeo.Net.Dns.DnsType.None)
            {
                throw new ArgumentOutOfRangeException("dnsType", "Not a valid value");
            }

            // sanity check the DnsClass parameter
            if (!Enum.IsDefined(typeof(Nequeo.Net.Dns.DnsClass), dnsClass) || dnsClass == Nequeo.Net.Dns.DnsClass.None)
            {
                throw new ArgumentOutOfRangeException("dnsClass", "Not a valid value");
            }

            // just remember the values
            _domain   = domain;
            _dnsType  = dnsType;
            _dnsClass = dnsClass;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start the asynchronous query request operation.
        /// </summary>
        /// <param name="domain">The domain to get records for.</param>
        /// <param name="dnsType">The dns record type to return.</param>
        /// <param name="dnsClass">The class to search in.</param>
        /// <param name="client">The current domain name client reference.</param>
        /// <param name="callback">The asynchronous call back method.</param>
        /// <param name="state">The state object value.</param>
        public AsyncDnsQueryRequest(string domain, Nequeo.Net.Dns.DnsType dnsType,
                                    Nequeo.Net.Dns.DnsClass dnsClass, DomainNameClient client, AsyncCallback callback, object state)
            : base(callback, state)
        {
            _client   = client;
            _domain   = domain;
            _dnsType  = dnsType;
            _dnsClass = dnsClass;

            ThreadPool.QueueUserWorkItem(new WaitCallback(AsyncQueryRequestThread1));
            Thread.Sleep(20);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Send a query to a domain name server to perform a
        /// lookup on the specified domian and return the records.
        /// </summary>
        /// <param name="domain">The domain to get records for.</param>
        /// <param name="dnsType">The dns record type to return.</param>
        /// <param name="dnsClass">The class to search in.</param>
        /// <returns>The response object containing the collection
        /// of domain name server information.</returns>
        public virtual Response Query(string domain, Nequeo.Net.Dns.DnsType dnsType,
                                      Nequeo.Net.Dns.DnsClass dnsClass)
        {
            // Validate the inputs.
            if (String.IsNullOrEmpty(domain))
            {
                throw new System.ArgumentNullException("Domain can not be null.",
                                                       new System.Exception("A valid domain should be specified."));
            }

            if (String.IsNullOrEmpty(_dnsServer))
            {
                throw new System.ArgumentNullException("Domain name server can not be null.",
                                                       new System.Exception("A valid domain name server should be specified."));
            }

            _domain = domain;

            // create a DNS request
            Request  request  = new Request();
            Resolver resolver = new Resolver();

            // create a question for this domain and DNS class.
            request.AddQuestion(new Question(domain, dnsType, dnsClass));

            // send it to the DNS server and get the response
            Response response = resolver.Lookup(request, _domain, _dnsPort, _dnsServer, _protocolType, _useIPv4EndPoint);

            // If the event has been attached
            // send to the client the data through
            // the delegate.
            if (OnQueryComplete != null)
            {
                OnQueryComplete(this, response);
            }

            // Return the response from the server.
            return(response);
        }