Beispiel #1
0
 public override string ToString()
 {
     if (IsResolved)
     {
         return(String.Format("{0} {1}",
                              Name.ToString(), String.Join(" ", Addresses.Select(a => String.Format("[{0}]", a.ToString())).ToArray())));
     }
     return(_Name.ToString());
 }
Beispiel #2
0
        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);
        }