コード例 #1
0
ファイル: DomainResolver.cs プロジェクト: Moerty/dnstools
        public Response LookUp(IPAddress address, QTYPE qtype, out Request request)
        {
            if (object.ReferenceEquals(null, Client))
            {
                throw new InvalidOperationException(
                          "A client must be associated with the resolver (use the Connect method).");
            }

            Response response;

            //if (LookUpProcessing != null)
            //  LookUpProcessing(this, new NameServerEventArgs(server, qtype, _Domain));

            //IPAddress address = server.GetFirstAddress(_Options.IPVersion);

            ushort id = (ushort)new Random(DateTime.Now.Millisecond).Next(0, ushort.MaxValue);

            request = new Request(id, false, OPCODE.QUERY, new Question(_Domain.ToString(), qtype));

            try
            {
                _Client.Connect(address);
                response = _Client.Process(request);
                if (response.Header.ID != id) // paranoid
                {
                    throw new ResolverException(
                              "Did not get my request ID back. Either the name server or the client software is buggy.");
                }
            }
            finally
            {
                _Client.Close();
            }

            return(response);
        }