示例#1
0
        public DnsQuestion(NetBinaryReader nbr)
        {
            List<string> labels = new List<string>();
            byte nameLength;

            while ((nameLength = nbr.ReadByte()) != 0)
            {
                string label = string.Empty;

                for (int i = 0; i < nameLength; i++)
                {
                    label += (char)nbr.ReadByte();
                }

                labels.Add(label);
            }

            QueriedDomainName = string.Join(".", labels);
            Type = (QType)nbr.ReadUInt16();

            ushort rawClass = nbr.ReadUInt16();
            if (rawClass > 65279) rawClass = 0;
            else if (rawClass > 4 && rawClass < 252) rawClass = 2;
            else if (rawClass > 255 && rawClass < 65280) rawClass = 2;
            Class = (DnsClass)rawClass;
        }
示例#2
0
            Duplicates;     // if any DNS lookup requests arrive with the same query they will be stored with the queued query.

            public LookupRequest(string hostname, QType queryType, int timeout, List <IPEndPoint> dnsServers,
                                 ManualResetEvent completeEvent)
            {
                Hostname      = hostname;
                QueryType     = queryType;
                Timeout       = timeout;
                DNSServers    = dnsServers;
                CompleteEvent = completeEvent;
            }
示例#3
0
 protected Resource(string name, QType type, QClass qClass, uint ttl, ushort length, string data)
 {
     Name   = name;
     Type   = type;
     Class  = qClass;
     Ttl    = ttl;
     Length = length;
     Data   = data;
 }
示例#4
0
        public mDNSQuestion(Byte[] data, int offset)
        {
            int idx = offset;

            name    = mDNSPacket.ReadName(data, ref idx);
            QType   = (QType)mDNSPacket.ReadUInt16(data, idx);
            QClass  = (QClass)mDNSPacket.ReadUInt16(data, (idx + 2));
            ByteLen = ((idx + 4) - offset);
        }
示例#5
0
        public static Dictionary <string, Variable> GetGlobals(string code)
        {
            Dictionary <string, Variable> vars = new Dictionary <string, Variable>();

            Variable      variable = new Variable();
            List <string> lines    = code.Split('\n').ToList();

            //Console.WriteLine("[DEBUG] Pass 2: getting globals");
            for (int i = 0; i < lines.Count; i++)
            {
                // Ignore lines that start with a //
                string line = lines[i].TrimStart(' ').TrimEnd(' ');
                if (line.StartsWith("//"))
                {
                    continue;
                }
                if (line.StartsWith("global_var"))
                {
                    // get the name
                    string[] split = line.Split('|');
                    if (split.Length > 4)
                    {
                        throw new ParseFailException(i, "Too many arguments to global_var!");
                    }
                    if (split.Length < 3)
                    {
                        throw new ParseFailException(i, "Invalid usage of global_var (usage: \"global_var|<type, int/string/bool/ri/rs/rb>|<your name>[|<default_value>]\")");
                    }
                    string name = split[2];
                    if (!IsValid.Identifier(name))
                    {
                        throw new ParseFailException(i, "Invalid function name");
                    }
                    if (vars.TryGetValue(name, out _))
                    {
                        throw new ParseFailException(i, "The " + name + " variable is already defined!");
                    }
                    QType qType = Misc.GetTypeFromString(i, split[1]);
                    variable.type = qType;

                    if (split.Length > 3)
                    {
                        variable.obj = Misc.GetObjectFromString(i, split[3], qType, vars);
                    }
                    else
                    {
                        variable.obj = Misc.GetDefaultObjectFromType(i, qType);
                    }
                    //Console.WriteLine($"[DEBUG] Found global {name} with value {variable.obj}");
                    vars.Add(name, variable);
                    variable = new Variable();
                }
            }

            return(vars);
        }
示例#6
0
 /// <summary>
 /// Order Initiate Message – q format b
 /// </summary>
 /// <param name="ts"></param>
 /// <param name="pri"></param>
 /// <param name="code"></param>
 /// <param name="ikey"></param>
 /// <param name="par"></param>
 public Message_q(int ts, int pri, int code, int ikey, List <int> par)
     : base("q")
 {
     m_QType = QType.B;
     m_TS    = ts;
     m_Pri   = pri;
     m_Code  = code;
     m_IKEY  = ikey;
     m_Par   = par;
 }
	public ObjectStats(string name, int id, QType qType, Direction direction, int weight, Transform prefab)
	{
		Name = name;
		ID = id;
		this.QType = qType;
		this.Direction = direction;
		Weight = weight;
		Prefab = prefab;

	}
示例#8
0
 protected DnsRecordClient(
     IDnsResolver dnsResolver,
     ILogger log,
     QType recordType,
     string recordName)
 {
     _dnsResolver = dnsResolver;
     _log         = log;
     _recordType  = recordType;
     _recordName  = recordName;
 }
示例#9
0
        public Question(string qName, QType qType, QClass qClass = QClass.IN)
        {
            if (!IsValidDomainName(qName))
            {
                throw new FormatException($"The domain name {qName} entered for QName is invalid!");
            }

            QName  = qName;
            QType  = qType;
            QClass = qClass;
        }
示例#10
0
        private QFunction ReadFunction(QType qtype)
        {
            switch (qtype)
            {
            case QType.Lambda:
            {
                _reader.ReadSymbol(_encoding);     // ignore context
                var expression = (char[])ReadObject();
                return(new QLambda(new string(expression)));
            }

            case QType.Projection:
            {
                var length     = _reader.ReadInt32();
                var parameters = new object[length];
                for (var i = 0; i < length; i++)
                {
                    parameters[i] = ReadObject();
                }
                return(new QProjection(parameters));
            }

            case QType.UnaryPrimitiveFunc:
            {
                var code = _reader.ReadByte();
                return(code == 0 ? null : QFunction.Create((byte)qtype));
            }

            case QType.BinaryPrimitiveFunc:
            case QType.TernaryOperatorFunc:
            {
                var code = _reader.ReadByte();     // ignore
                return(QFunction.Create((byte)qtype));
            }

            case QType.CompositionFunc:
            {
                var length     = _reader.ReadInt32();
                var parameters = new object[length];
                for (var i = 0; i < length; i++)
                {
                    parameters[i] = ReadObject();
                }
                return(QFunction.Create((byte)qtype));
            }

            default:
            {
                ReadObject();     // ignore
                return(QFunction.Create((byte)qtype));
            }
            }
        }
示例#11
0
        public DnsAnswer(NetBinaryReader nbr)
        {
            Name = nbr.ReadLblOrPntString();
            Type = (QType)nbr.ReadUInt16();

            ushort rawClass = nbr.ReadUInt16();
            if (rawClass > 65279) rawClass = 0;
            else if (rawClass > 4 && rawClass < 252) rawClass = 2;
            else if (rawClass > 255 && rawClass < 65280) rawClass = 2;
            Class = (DnsClass)rawClass;

            TTL = nbr.ReadUInt32();
            ByteCount = nbr.ReadUInt16();
            HandleRData(nbr);
        }
示例#12
0
        public IList <string> CertRecords(string name)
        {
            IList <string> records = new List <string>();
            const QType    qType   = QType.CERT;
            const QClass   qClass  = QClass.IN;

            Response response = _resolver.Query(name, qType, qClass);

            foreach (RecordCERT record in response.RecordsCERT)
            {
                records.Add(record.ToString());
            }

            return(records);
        }
示例#13
0
        /// <summary>
        /// Do an QClass=IN Query on specified DNS servers
        /// </summary>
        /// <param name="name">Name to query</param>
        /// <param name="qtype">Question type</param>
        /// <returns>Response of the query</returns>
        public Response Query(string name, QType qtype)
        {
            Question question = new Question(name, qtype, QClass.IN);
            Response response = SearchInCache(question);

            if (response != null)
            {
                return(response);
            }

            Request request = new Request();

            request.AddQuestion(question);
            return(GetResponse(request));
        }
示例#14
0
        /// <summary>
        /// Do Query on specified DNS servers
        /// </summary>
        /// <param name="name">Name to query</param>
        /// <param name="qtype">Question type</param>
        /// <param name="qclass">Class type</param>
        /// <returns>Response of the query</returns>
        public Response Query(string name, QType qtype, QClass qclass)
        {
            var question = new Question(name, qtype, qclass);
            var response = SearchInCache(question);

            if (response != null)
            {
                return(response);
            }

            var request = new Request();

            request.AddQuestion(question);
            return(GetResponse(request));
        }
示例#15
0
        /// <summary>
        /// Do Query on specified DNS servers
        /// </summary>
        /// <param name="name">Name to query</param>
        /// <param name="qtype">Question type</param>
        /// <param name="timeout">Timeout for lookup in seconds.</param>
        /// <param name="qclass">Class type</param>
        /// <returns>Response of the query</returns>
        public DNSResponse Query(string name, QType qtype, QClass qclass, int timeout)
        {
            Question    question = new Question(name, qtype, qclass);
            DNSResponse response = SearchInCache(question);

            if (response != null)
            {
                return(response);
            }

            DNSRequest request = new DNSRequest();

            request.AddQuestion(question);
            return(GetResponse(request, m_DnsServers, timeout));
        }
示例#16
0
        /// <summary>
        ///     Returns default mapping for particular q type.
        /// </summary>
        /// <param name="type">Requested q type</param>
        /// <returns>Type of the object being a result of q message deserialization</returns>
        public static Type GetType(QType type)
        {
            if (FromQ.ContainsKey(type))
            {
                return(FromQ[type]);
            }
            switch (type)
            {
            case QType.NullItem:
                return(null);

            default:
                throw new QReaderException("Cannot deserialize object of type: " + type);
            }
        }
示例#17
0
    public void Show(QType type = QType.Practice)
    {
        currentQType = type;
        myPanel.Show();
        qTitleText.text = "";


        hintCloud.DOFade(1, 1).SetDelay(1).OnComplete(() =>
        {
            hintCloud.DOFade(0, 2).SetDelay(3);
        }
                                                      );

        Restart();
    }
示例#18
0
        public DNSResponse Query(string name, QType qtype, int timeout, List <IPEndPoint> dnsServers)
        {
            Question    question = new Question(name, qtype, QClass.IN);
            DNSResponse response = SearchInCache(question);

            if (response != null)
            {
                return(response);
            }

            DNSRequest request = new DNSRequest();

            request.AddQuestion(question);
            return(GetResponse(request, dnsServers, timeout));
        }
示例#19
0
        private Response CreateRecord(string domainName, string[] records, bool hasError = false)
        {
            QType  dnsEntryType = QType.MX;
            Class  dnsClass     = Class.IN;
            UInt32 ttl          = 3600;

            byte nameTerminator = 0;

            byte[] domainNameBytes   = Encoding.UTF8.GetBytes(domainName);
            byte[] dnsEntryTypeBytes = BitConverter.GetBytes((UInt16)dnsEntryType).Reverse().ToArray();
            byte[] dnsClassBytes     = BitConverter.GetBytes((UInt16)dnsClass).Reverse().ToArray();
            byte[] ttlBytes          = BitConverter.GetBytes(ttl).Reverse().ToArray();
            byte[] lengthBytes       = BitConverter.GetBytes((UInt16)0).Reverse().ToArray();


            Response response = new Response();

            if (hasError)
            {
                response.header.RCODE = RCode.ServFail;
            }

            for (int i = 0; i < records.Length; i++)
            {
                byte[] preferenceBytes = BitConverter.GetBytes((UInt16)i).Reverse().ToArray();
                byte[] recordBytes     = Encoding.UTF8.GetBytes(records[i]);

                using (MemoryStream memoryStream = new MemoryStream())
                {
                    memoryStream.WriteByte((byte)domainNameBytes.Length);
                    memoryStream.Write(domainNameBytes, 0, domainNameBytes.Length);
                    memoryStream.WriteByte(nameTerminator);
                    memoryStream.Write(dnsEntryTypeBytes, 0, dnsEntryTypeBytes.Length);
                    memoryStream.Write(dnsClassBytes, 0, dnsClassBytes.Length);
                    memoryStream.Write(ttlBytes, 0, ttlBytes.Length);
                    memoryStream.Write(lengthBytes, 0, lengthBytes.Length);
                    memoryStream.Write(preferenceBytes, 0, preferenceBytes.Length);
                    memoryStream.WriteByte((byte)recordBytes.Length);
                    memoryStream.Write(recordBytes, 0, recordBytes.Length);
                    memoryStream.WriteByte(nameTerminator);

                    response.Answers.Add(new AnswerRR(new RecordReader(memoryStream.ToArray())));
                }
            }

            return(response);
        }
示例#20
0
        /// <summary>
        /// 发送测试DNS请求
        /// </summary>
        private async void  SendDNSRequestAsync()
        {
            DNSRequest request = DNSRequest.Instance;
            IPAddress  server;

            try//检测IP是否合法
            {
                server = IPAddress.Parse(model.SiteAddress);
            }
            catch
            {
                await new MessageDialog("SiteAddress is wrong").ShowAsync();
                return;
            }
            QType type = QType.A;     //默认值为A

            switch (model.RecordType) //获取QType
            {
            case 0:
                type = QType.A;
                break;

            case 1:
                type = QType.CNAME;
                break;

            case 2:
                type = QType.NS;
                break;

            case 3:
                type = QType.MX;
                break;

            default:
                break;
            }
            request.DomainName = model.Lookup;
            request.RecordType = type;
            request.DnsServer  = server;
            await request.MakeRequest();

            await new MessageDialog(request.RequestInfos).ShowAsync();//显示返回信息
        }
示例#21
0
        private Response CreateRecord(string domainName, string[][] records, RCode responseCode = RCode.NoError)
        {
            Response response = new Response {
                header = { RCODE = responseCode }
            };

            foreach (var record in records)
            {
                QType dnsEntryType = QType.TXT;
                Class dnsClass     = Class.IN;

                byte nameTerminator = 0;

                byte[]   domainNameBytes   = Encoding.UTF8.GetBytes(domainName);
                byte[]   dnsEntryTypeBytes = BitConverter.GetBytes((UInt16)dnsEntryType).Reverse().ToArray();
                byte[]   dnsClassBytes     = BitConverter.GetBytes((UInt16)dnsClass).Reverse().ToArray();
                byte[]   ttlBytes          = BitConverter.GetBytes(3600).Reverse().ToArray();
                byte[][] recordsBytes      = record.Select(_ => Encoding.UTF8.GetBytes(_)).ToArray();
                byte[]   lengthBytes       =
                    BitConverter.GetBytes((UInt16)recordsBytes.Sum(_ => _.Length)).Reverse().ToArray();


                using (MemoryStream memoryStream = new MemoryStream())
                {
                    memoryStream.WriteByte((byte)domainNameBytes.Length);
                    memoryStream.Write(domainNameBytes, 0, domainNameBytes.Length);
                    memoryStream.WriteByte(nameTerminator);
                    memoryStream.Write(dnsEntryTypeBytes, 0, dnsEntryTypeBytes.Length);
                    memoryStream.Write(dnsClassBytes, 0, dnsClassBytes.Length);
                    memoryStream.Write(ttlBytes, 0, ttlBytes.Length);
                    memoryStream.Write(lengthBytes, 0, lengthBytes.Length);

                    foreach (var bytes in recordsBytes)
                    {
                        memoryStream.WriteByte((byte)bytes.Length);
                        memoryStream.Write(bytes, 0, bytes.Length);
                    }

                    response.Answers.Add(new AnswerRR(new RecordReader(memoryStream.ToArray())));
                }
            }

            return(response);
        }
示例#22
0
        private static List <string> GetColumns(QType qType, bool checkIdentity = true)
        {
            var columns    = new List <string>();
            var properties = typeof(TSource).GetProperties();

            foreach (var v in properties)
            {
                if (IsValidPropertyType(v.PropertyType))
                {
                    var attribute = v.GetCustomAttributes(false);
                    if (qType == QType.Select)
                    {
                        var hasAttrubute = attribute.FirstOrDefault(a => a.GetType() == typeof(NotMappedAttribute));
                        if (hasAttrubute == null)
                        {
                            columns.Add(v.Name);
                        }
                    }
                    if (qType == QType.Insert || qType == QType.Update || qType == QType.Delete)
                    {
                        object hasAttrubute;
                        if (checkIdentity)
                        {
                            hasAttrubute =
                                attribute.FirstOrDefault(
                                    a => a is KeyAttribute || a.GetType() == typeof(NotMappedAttribute));
                        }
                        else
                        {
                            hasAttrubute = attribute.FirstOrDefault(a => a.GetType() == typeof(NotMappedAttribute));
                        }

                        if (hasAttrubute == null)
                        {
                            columns.Add(v.Name);
                        }
                    }
                }
            }
            return(columns);
        }
示例#23
0
        public Response Query(string hostName, QType type, QClass @class)
        {
            if (String.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentException("Invalid host name", "hostName");
            }

            var question = new Question(hostName, type, @class);
            var response = FindResponse(question);

            if (response != null)
            {
                return(response);
            }

            var request = new Request();

            request.AddQuestion(question);
            response = GetResponse(request);
            return(response);
        }
示例#24
0
        public static object GetDefaultObjectFromType(int line, QType type)
        {
            switch (type)
            {
            case QType.Bool:
            {
                return(false);
            }

            case QType.String:
            {
                return("");
            }

            case QType.Int:
            {
                return(0);
            }
            }
            return(null);
        }
示例#25
0
        /// <summary>
        /// Performs a Trace on query
        /// </summary>
        /// <param name="name"></param>
        /// <param name="qtype"></param>
        /// <param name="qclass"></param>
        public void Trace(string name, QType qtype, QClass qclass)
        {
            Message("; <<>> DigTrace.Net {0} <<>> @{1} {2} {3}", resolver.Version, resolver.DnsServer, qtype, name);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Message(";; Loading Root nameservers");
            var rootaddresses = resolver.LoadRootFile();

            foreach (var ra in rootaddresses)
            {
                //Message(";; Asking {0} ({1}) for nameserver for {2} ", ra.Key, ra.Value, name);
                var nsaddress = TraceNameservers(name, ra, qtype, qclass, true);
                if (nsaddress != null)
                {
                    Message(";; Using {0} as nameserver for {1}", nsaddress, name);
                    resolver.DnsServer = nsaddress.ToString();
                    break;
                }
            }

            Response response = resolver.Query(name, qtype, qclass);

            sw.Stop();

            if (response.Error != "")
            {
                Message(";; " + response.Error);
                return;
            }

            PrintAnswer(response);

            Message(";; Query time: {0} msec", sw.ElapsedMilliseconds);
            Message(";; SERVER: {0}#{1}({2})", response.Server.Address, response.Server.Port, response.Server.Address);
            Message(";; WHEN: " + response.TimeStamp.ToString("ddd MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture));
            Message(";; MSG SIZE rcvd: " + response.MessageSize);
        }
示例#26
0
        int Dequeue(QType q)
        {
            nekara.ContextSwitch();
            int x = q.Element[q.Head];

            nekara.ContextSwitch();
            q.Amount--;

            nekara.ContextSwitch();
            if (q.Head == this.Size)
            {
                nekara.ContextSwitch();
                q.Head = 1;
            }
            else
            {
                nekara.ContextSwitch();
                q.Head++;
            }

            return(x);
        }
示例#27
0
        /// <summary>
        /// Will parse resource data (DNS Answers) into IResource. The concrete type will be the answer type eg. MX = MxRecord Type
        /// </summary>
        /// <param name="data"></param>
        /// <param name="receiveDnsPacket"></param>
        /// <returns></returns>
        public static IEnumerable <IResource> Parse(byte[] data, ReceiveDnsPacket receiveDnsPacket)
        {
            IResource[] resources = new IResource[receiveDnsPacket.Header.AnswersCounts];
            int         position  = receiveDnsPacket.ToBytes().Length;

            for (var i = 0; i < receiveDnsPacket.Header.AnswersCounts; i++)
            {
                var walkedHostname = GetRecordName(ref data, position);

                string name         = walkedHostname.hostname.ToString();
                QType  type         = (QType)Enum.Parse(typeof(QType), ((int)data[walkedHostname.pos + 1]).ToString());
                QClass qClass       = (QClass)Enum.Parse(typeof(QClass), ((int)data[walkedHostname.pos + 3]).ToString());
                uint   ttl          = BitConverter.ToUInt16(new[] { data[walkedHostname.pos + 5], data[walkedHostname.pos + 6], data[walkedHostname.pos + 7], data[walkedHostname.pos + 8] }, 0);
                ushort length       = data[walkedHostname.pos + 9];
                var    resourceData = ReadAnswer(ref data, walkedHostname.pos + 10, new Resource(name, type, qClass, ttl, length, null));

                position     = walkedHostname.pos + 10 + length;
                resources[i] = resourceData;
            }

            return(resources);
        }
示例#28
0
        int Enqueue(QType q, int x)
        {
            nekara.ContextSwitch();
            q.Element[q.Tail] = x;

            nekara.ContextSwitch();
            q.Amount++;

            nekara.ContextSwitch();
            if (q.Tail == this.Size)
            {
                nekara.ContextSwitch();
                q.Tail = 1;
            }
            else
            {
                nekara.ContextSwitch();
                q.Tail++;
            }

            return(0);
        }
        public ActionResult RedirectQues(string QuesId)
        {
            int myQuesId              = int.Parse(QuesId);
            ApplicationDbContext db   = new ApplicationDbContext();
            Question             Ques = (from q in db.Questions where q.id == myQuesId select q).First();
            QType QuesT = (from q in db.Questions
                           join qt in db.QTypes on q.Type.id equals qt.id
                           where q.id == myQuesId
                           select qt).First();

            switch (QuesT.id)
            {
            case 1:
                return(RedirectToAction("ReturnPuzzle", "Teacher", Ques));

            case 2:
                return(ReturnQuiz(Ques));

            case 3:
                return(RedirectToAction("ReturnTranslate", "Teacher", Ques));
            }
            return(RedirectToAction("RedirectFailed", "Teacher"));
        }
示例#30
0
        /// <summary>
        /// Dig a query
        /// </summary>
        /// <param name="name"></param>
        /// <param name="qtype"></param>
        /// <param name="qclass"></param>
        public void DigIt(string name, QType qtype, QClass qclass)
        {
            Message("; <<>> Dig.Net {0} <<>> @{1} {2} {3}", resolver.Version, resolver.DnsServer, qtype, name);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Response response = resolver.Query(name, qtype, qclass);

            sw.Stop();

            if (response.Error != "")
            {
                Message(";; " + response.Error);
                return;
            }

            PrintAnswer(response);

            Message(";; Query time: {0} msec", sw.ElapsedMilliseconds);
            Message(";; SERVER: {0}#{1}({2})", response.Server.Address, response.Server.Port, response.Server.Address);
            Message(";; WHEN: " + response.TimeStamp.ToString("ddd MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture));
            Message(";; MSG SIZE rcvd: " + response.MessageSize);
        }
示例#31
0
文件: Resolver.cs 项目: Cotoff/xmpp
        /// <summary>
        /// Do Query on specified DNS servers
        /// </summary>
        /// <param name="name">Name to query</param>
        /// <param name="qtype">Question type</param>
        /// <param name="qclass">Class type</param>
        /// <returns>Response of the query</returns>
        public Response Query(string name, QType qtype, QClass qclass)
        {
            var question = new Question(name, qtype, qclass);
            var response = SearchInCache(question);
            if (response != null)
                return response;

            var request = new Request();
            request.AddQuestion(question);
            return GetResponse(request);
        }
示例#32
0
        /// <summary>
        /// Do an QClass=IN Query on the previously cached results.
        /// </summary>
        /// <param name="name">Name to query</param>
        /// <param name="qtype">Question type</param>
        /// <returns>Response of the query</returns>
        public DNSResponse QueryCache(string name, QType qtype, QClass qclass)
        {
            Question question = new Question(name, qtype, qclass);

            return(SearchInCache(question));
        }
示例#33
0
 private void WriteAtom(object obj, QType qtype)
 {
     writer.Write((sbyte)qtype);
     switch (qtype)
     {
         case QType.Bool:
             writer.Write((bool)obj);
             return;
         case QType.Byte:
             writer.Write((byte)obj);
             return;
         case QType.Guid:
             if (protocolVersion < 3)
             {
                 throw new QWriterException("kdb+ protocol version violation: guid not supported pre kdb+ v3.0");
             }
             WriteGuid((Guid)obj);
             return;
         case QType.Short:
             writer.Write((short)obj);
             return;
         case QType.Int:
             writer.Write((int)obj);
             return;
         case QType.Long:
             writer.Write((long)obj);
             return;
         case QType.Float:
             writer.Write((float)obj);
             return;
         case QType.Double:
             writer.Write((double)obj);
             return;
         case QType.Char:
             writer.Write((char)obj);
             return;
         case QType.Symbol:
             WriteSymbol(obj as string);
             return;
         case QType.Timestamp:
             if (protocolVersion < 1)
             {
                 throw new QWriterException("kdb+ protocol version violation: timestamp not supported pre kdb+ v2.6");
             }
             writer.Write(((QTimestamp)obj).Value);
             return;
         case QType.Month:
             writer.Write(((QMonth)obj).Value);
             return;
         case QType.Date:
             writer.Write(((QDate)obj).Value);
             return;
         case QType.Datetime:
             writer.Write(((QDateTime)obj).Value);
             return;
         case QType.Timespan:
             if (protocolVersion < 1)
             {
                 throw new QWriterException("kdb+ protocol version violation: timespan not supported pre kdb+ v2.6");
             }
             writer.Write(((QTimespan)obj).Value);
             return;
         case QType.Minute:
             writer.Write(((QMinute)obj).Value);
             return;
         case QType.Second:
             writer.Write(((QSecond)obj).Value);
             return;
         case QType.Time:
             writer.Write(((QTime)obj).Value);
             return;
     }
     throw new QWriterException("Unable to serialize q atom of type: " + qtype);
 }
示例#34
0
 public Question(RecordReader rr)
 {
     QName = rr.ReadDomainName();
     QType = (QType)rr.ReadUInt16();
     QClass = (QClass)rr.ReadUInt16();
 }
示例#35
0
 public QToken(QType t)
 {
     TokenType = t;
 }
示例#36
0
 /// <summary>
 ///     Returns object representing q null of particular type.
 /// </summary>
 /// <param name="type">Requested null type</param>
 /// <returns>object representing q null</returns>
 public static object GetQNull(QType type)
 {
     if (qNulls.ContainsKey(type))
     {
         return qNulls[type];
     }
     throw new QException("Cannot find null value of type: " + type);
 }
示例#37
0
 /// <summary>
 /// Starts a Dig operation
 /// </summary>
 /// <param name="name"></param>
 /// <param name="qtype"></param>
 /// <param name="qclass"></param>
 public void BeginDigIt(string name, QType qtype, QClass qclass)
 {
     DigItDelegate d = new DigItDelegate(DigIt);
     d.BeginInvoke(name, qtype, qclass, null, null);
 }
示例#38
0
 private void WriteList(Array list, QType qtype)
 {
     writer.Write((sbyte)qtype);
     writer.Write((byte)0); // attributes
     writer.Write(list.Length);
     switch (qtype)
     {
         case QType.BoolList:
             {
                 var _list = list as bool[];
                 if (_list != null)
                     foreach (bool a in _list)
                     {
                         writer.Write(a);
                     }
                 return;
             }
         case QType.ByteList:
             {
                 var _list = list as byte[];
                 if (_list != null)
                     foreach (byte a in _list)
                     {
                         writer.Write(a);
                     }
                 return;
             }
         case QType.GuidList:
             {
                 if (protocolVersion < 3)
                 {
                     throw new QWriterException("kdb+ protocol version violation: guid not supported pre kdb+ v3.0");
                 }
                 var _list = list as Guid[];
                 if (_list != null)
                     foreach (Guid a in _list)
                     {
                         WriteGuid(a);
                     }
                 return;
             }
         case QType.ShortList:
             {
                 var _list = list as short[];
                 if (_list != null)
                     foreach (short a in _list)
                     {
                         writer.Write(a);
                     }
                 return;
             }
         case QType.IntList:
             {
                 var _list = list as int[];
                 if (_list != null)
                     foreach (int a in _list)
                     {
                         writer.Write(a);
                     }
                 return;
             }
         case QType.LongList:
             {
                 var _list = list as long[];
                 if (_list != null)
                     foreach (long a in _list)
                     {
                         writer.Write(a);
                     }
                 return;
             }
         case QType.FloatList:
             {
                 var _list = list as float[];
                 if (_list != null)
                     foreach (float a in _list)
                     {
                         writer.Write(a);
                     }
                 return;
             }
         case QType.DoubleList:
             {
                 var _list = list as double[];
                 if (_list != null)
                     foreach (double a in _list)
                     {
                         writer.Write(a);
                     }
                 return;
             }
         case QType.SymbolList:
             {
                 var _list = list as string[];
                 if (_list != null)
                     foreach (string a in _list)
                     {
                         WriteSymbol(a);
                     }
                 return;
             }
         case QType.TimestampList:
             {
                 if (protocolVersion < 1)
                 {
                     throw new QWriterException("kdb+ protocol version violation: timestamp not supported pre kdb+ v2.6");
                 }
                 var _list = list as QTimestamp[];
                 if (_list != null)
                     foreach (QTimestamp a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
         case QType.MonthList:
             {
                 var _list = list as QMonth[];
                 if (_list != null)
                     foreach (QMonth a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
         case QType.DateList:
             {
                 var _list = list as QDate[];
                 if (_list != null)
                     foreach (QDate a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
         case QType.DatetimeList:
             {
                 var _list = list as QDateTime[];
                 if (_list != null)
                     foreach (QDateTime a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
         case QType.TimespanList:
             {
                 if (protocolVersion < 1)
                 {
                     throw new QWriterException("kdb+ protocol version violation: timespan not supported pre kdb+ v2.6");
                 }
                 var _list = list as QTimespan[];
                 if (_list != null)
                     foreach (QTimespan a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
         case QType.MinuteList:
             {
                 var _list = list as QMinute[];
                 if (_list != null)
                     foreach (QMinute a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
         case QType.SecondList:
             {
                 var _list = list as QSecond[];
                 if (_list != null)
                     foreach (QSecond a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
         case QType.TimeList:
             {
                 var _list = list as QTime[];
                 if (_list != null)
                     foreach (QTime a in _list)
                     {
                         writer.Write((a).Value);
                     }
                 return;
             }
     }
     throw new QWriterException("Unable to serialize q vector of type: " + qtype);
 }
示例#39
0
        public Response Query(string hostName, QType type, QClass @class)
        {
            if (String.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentException("Invalid host name", "hostName");
            }

            var question = new Question(hostName, type, @class);
            var response = FindResponse(question);
            if (response != null)
            {
                return response;
            }

            var request = new Request();
            request.AddQuestion(question);
            response = GetResponse(request);
            return response;
        }
示例#40
0
		public void DigIt(string name, QType qtype)
		{
			DigIt(name, qtype, QClass.IN);
		}
示例#41
0
文件: QReader.cs 项目: mrecht/qSharp
 private QFunction ReadFunction(QType qtype)
 {
     switch (qtype)
     {
         case QType.Lambda:
         {
             _reader.ReadSymbol(_encoding); // ignore context
             var expression = (char[]) ReadObject();
             return new QLambda(new string(expression));
         }
         case QType.Projection:
         {
             var length = _reader.ReadInt32();
             var parameters = new object[length];
             for (var i = 0; i < length; i++)
             {
                 parameters[i] = ReadObject();
             }
             return new QProjection(parameters);
         }
         case QType.UnaryPrimitiveFunc:
         {
             var code = _reader.ReadByte();
             return code == 0 ? null : QFunction.Create((byte) qtype);
         }
         case QType.BinaryPrimitiveFunc:
         case QType.TernaryOperatorFunc:
         {
             var code = _reader.ReadByte(); // ignore
             return QFunction.Create((byte) qtype);
         }
         case QType.CompositionFunc:
         {
             var length = _reader.ReadInt32();
             var parameters = new object[length];
             for (var i = 0; i < length; i++)
             {
                 parameters[i] = ReadObject();
             }
             return QFunction.Create((byte) qtype);
         }
         default:
         {
             ReadObject(); // ignore
             return QFunction.Create((byte) qtype);
         }
     }
 }
示例#42
0
 public QToken(QType t, object p)
 {
     TokenType = t; Param = p;
 }
示例#43
0
文件: QReader.cs 项目: mrecht/qSharp
        private object ReadList(QType qtype)
        {
            _reader.ReadByte(); // attributes
            var length = _reader.ReadInt32();

            switch (qtype)
            {
                case QType.BoolList:
                {
                    var list = new bool[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadBoolean();
                    }
                    return list;
                }
                case QType.ByteList:
                {
                    var list = new byte[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadByte();
                    }
                    return list;
                }
                case QType.GuidList:
                {
                    var list = new Guid[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadGuid();
                    }
                    return list;
                }
                case QType.ShortList:
                {
                    var list = new short[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadInt16();
                    }
                    return list;
                }
                case QType.IntList:
                {
                    var list = new int[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadInt32();
                    }
                    return list;
                }
                case QType.LongList:
                {
                    var list = new long[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadInt64();
                    }
                    return list;
                }
                case QType.FloatList:
                {
                    var list = new float[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadSingle();
                    }
                    return list;
                }
                case QType.DoubleList:
                {
                    var list = new double[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = _reader.ReadDouble();
                    }
                    return list;
                }
                case QType.String:
                {
                    return _encoding.GetChars(_reader.ReadBytes(length));
                }
                case QType.SymbolList:
                {
                    var list = new string[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = ReadSymbol();
                    }
                    return list;
                }
                case QType.TimestampList:
                {
                    var list = new QTimestamp[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QTimestamp(_reader.ReadInt64());
                    }
                    return list;
                }
                case QType.MonthList:
                {
                    var list = new QMonth[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QMonth(_reader.ReadInt32());
                    }
                    return list;
                }
                case QType.DateList:
                {
                    var list = new QDate[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QDate(_reader.ReadInt32());
                    }
                    return list;
                }
                case QType.DatetimeList:
                {
                    var list = new QDateTime[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QDateTime(_reader.ReadDouble());
                    }
                    return list;
                }
                case QType.TimespanList:
                {
                    var list = new QTimespan[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QTimespan(_reader.ReadInt64());
                    }
                    return list;
                }
                case QType.MinuteList:
                {
                    var list = new QMinute[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QMinute(_reader.ReadInt32());
                    }
                    return list;
                }
                case QType.SecondList:
                {
                    var list = new QSecond[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QSecond(_reader.ReadInt32());
                    }
                    return list;
                }
                case QType.TimeList:
                {
                    var list = new QTime[length];
                    for (var i = 0; i < length; i++)
                    {
                        list[i] = new QTime(_reader.ReadInt32());
                    }
                    return list;
                }
            }
            throw new QReaderException("Unable to deserialize q vector of type: " + qtype);
        }
示例#44
0
    //public void Decrement(int q)
    //{
    //    if (q >= 0 && q < QSize)
    //        mQuad[q]--;
    //}
    public void merge(Node l, Node r)
    {
        r = r == null ? new Node() : r;
        l = l == null ? new Node() : l;
        for (int i = 0; i < QSize; ++i)
        {
            mQuad[i] = l.mQuad[i] + r.mQuad[i];
        }

        // Rest Qtype
        qType = QType.None;
    }
示例#45
0
			public QuerySet(string Name, QType Type, QClass Class)
			{
				this.Name = Name;
				this.Type = Type;
				this.Class = Class;
			}
示例#46
0
 public void SetType(QType t)
 {
     if (t == QType.X)
     {
         switch (qType)
         {
             case QType.X: qType = QType.None; break;
             case QType.Y: qType = QType.XY; break;
             case QType.XY: qType = QType.Y; break;
             case QType.None: qType = QType.X; break;
         }
     }
     else if (t == QType.Y)
     {
         switch (qType)
         {
             case QType.X: qType = QType.XY; break;
             case QType.Y: qType = QType.None; break;
             case QType.XY: qType = QType.X; break;
             case QType.None: qType = QType.Y; break;
         }
     }
     else if (t == QType.XY)
     {
         switch (qType)
         {
             case QType.X: qType = QType.Y; break;
             case QType.Y: qType = QType.X; break;
             case QType.XY: qType = QType.None; break;
             case QType.None: qType = QType.XY; break;
         }
     }
 }
示例#47
0
 /// <summary>
 ///     Returns default mapping for particular q type.
 /// </summary>
 /// <param name="type">Requested q type</param>
 /// <returns>Type of the object being a result of q message deserialization</returns>
 public static Type GetType(QType type)
 {
     if (fromQ.ContainsKey(type))
     {
         return fromQ[type];
     }
     switch (type)
     {
         case QType.NullItem:
             return null;
         default:
             throw new QReaderException("Cannot deserialize object of type: " + type);
     }
 }
示例#48
0
    public void Transform()
    {
        int tmp = 0;
        switch (qType)
        {
            case QType.Y:
                tmp = mQuad[0];
                mQuad[0] = mQuad[1];
                mQuad[1] = tmp;
                tmp = mQuad[2];
                mQuad[2] = mQuad[3];
                mQuad[3] = tmp;
                break;
            case QType.X:
                tmp = mQuad[0];
                mQuad[0] = mQuad[3];
                mQuad[3] = tmp;
                tmp = mQuad[2];
                mQuad[2] = mQuad[1];
                mQuad[1] = tmp;
                break;
            case QType.XY:
                tmp = mQuad[0];
                mQuad[0] = mQuad[2];
                mQuad[2] = tmp;
                tmp = mQuad[1];
                mQuad[1] = mQuad[3];
                mQuad[3] = tmp;
                break;
            case QType.None:
                break;
            default:
                break;
        }

        // Set Qtype to None after transform
        qType = QType.None;
    }
示例#49
0
 public Question(string QName,QType QType,QClass QClass)
 {
     this.QName = QName;
     this.QType = QType;
     this.QClass = QClass;
 }
示例#50
0
 // Update Values for Points in Tree
 public void Update(int uBegin, int uEnd, QType type)
 {
     Update(1, uBegin, uEnd, type);
 }
示例#51
0
        /// <summary>
        /// Do an QClass=IN Query on specified DNS servers
        /// </summary>
        /// <param name="name">Name to query</param>
        /// <param name="qtype">Question type</param>
        /// <returns>Response of the query</returns>
        public Response Query(string name, QType qtype)
        {
            Question question = new Question(name, qtype, QClass.IN);
            Response response = SearchInCache(question);
            if (response != null)
                return response;

            Request request = new Request();
            request.AddQuestion(question);
            return GetResponse(request);
        }
示例#52
0
    // Update this to do a range update
    //    Take in a range for udating the xflips and yflips
    //    Need to drill down to leafs and update them then merge
    //    Very similar to BuildTree
    private Node Update(int idx, int uBegin, int uEnd, QType type)
    {
        Node seg = mSegTree[idx - 1];
        if (idx >= mMaxNodes || !seg.IsValid())
            return new Node();

        // Update node if in range
        if (seg.IsLeaf())
        {
            seg.SetType(type);
            seg.Transform();
            return seg;
        }

        // Retrive Child nodes and set type
        int leftIdx = GetLeftChild(idx);
        int rightIdx = GetRightChild(idx);
        Node lSeg = mSegTree[leftIdx - 1] != null ? mSegTree[leftIdx - 1] : new Node();
        Node rSeg = mSegTree[rightIdx - 1] != null ? mSegTree[rightIdx - 1] : new Node();

        if (uBegin <= seg.Start && seg.End <= uEnd)
        {
            // Set Type
            seg.SetType(type);

            // Set QType for child segment nodes
            lSeg.SetType(seg.GetQType());
            rSeg.SetType(seg.GetQType());

            // Transfrom Quads
            seg.Transform();
            return seg;
        }

        // Propogate the changes down the tree.
        lSeg.SetType(seg.GetQType());
        rSeg.SetType(seg.GetQType());
        seg.SetType(seg.GetQType()); // Reset to NONE

        // Query Child nodes
        Node left = leftIdx < mMaxNodes && uBegin <= lSeg.End ?
            Update(leftIdx, uBegin, uEnd, type) :
            Update(leftIdx, lSeg.Start, lSeg.End, QType.None);
        Node right = rightIdx < mMaxNodes && uEnd >= rSeg.Start ?
            Update(rightIdx, uBegin, uEnd, type) :
            Update(rightIdx, rSeg.Start, rSeg.End, QType.None);

        seg.merge(left, right);
        return seg;
    }
示例#53
0
        public static DNSResponse Lookup(string hostname, QType queryType, int timeout, List <IPEndPoint> dnsServers, bool useCache, bool async)
        {
            if (hostname == null || hostname.Trim().Length == 0)
            {
                return(null);
            }

            DNSResponse ipAddressResult = MatchIPAddress(hostname);

            if (ipAddressResult != null)
            {
                return(ipAddressResult);
            }
            else if (useCache)
            {
                DNSResponse cacheResult = m_resolver.QueryCache(hostname.Trim().ToLower(), queryType);
                if (cacheResult != null)
                {
                    return(cacheResult);
                }
            }

            if (async)
            {
                //logger.LogDebug("DNS lookup cache miss for async lookup to " + queryType.ToString() + " " + hostname + ".");
                QueueLookup(new LookupRequest(hostname.Trim().ToLower(), queryType, timeout, dnsServers, null));
                return(null);
            }
            else
            {
                ManualResetEvent completeEvent = new ManualResetEvent(false);
                QueueLookup(new LookupRequest(hostname.Trim().ToLower(), queryType, timeout, dnsServers, completeEvent));

                if (completeEvent.WaitOne(timeout * 1000 * 2, false))
                {
                    //logger.LogDebug("Complete event fired for DNS lookup on " + queryType.ToString() + " " + hostname + ".");
                    // Completed event was fired, the DNS entry will now be in cache.
                    DNSResponse result = m_resolver.QueryCache(hostname, queryType);
                    if (result != null)
                    {
                        return(result);
                    }
                    else
                    {
                        //logger.LogDebug("DNS lookup cache miss for " + queryType.ToString() + " " + hostname + ".");
                        // Timeout.
                        DNSResponse timeoutResponse = new DNSResponse();
                        timeoutResponse.Timedout = true;
                        return(timeoutResponse);
                    }
                }
                else
                {
                    // If this block gets called it's because the DNS resolver class did not return within twice the timeout period it
                    // was asked to do so in. If this happens a lot further investigation into the DNS resolver class is warranted.
                    logger.LogError("DNSManager timed out waiting for the DNS resolver to complete the lookup for " + queryType.ToString() + " " + hostname + ".");

                    // Timeout.
                    DNSResponse timeoutResponse = new DNSResponse();
                    timeoutResponse.Timedout = true;
                    return(timeoutResponse);
                }
            }
        }
示例#54
0
文件: QReader.cs 项目: mrecht/qSharp
        private object ReadAtom(QType qtype)
        {
            switch (qtype)
            {
                case QType.Bool:
                    return _reader.ReadBoolean();
                case QType.Byte:
                    return _reader.ReadByte();
                case QType.Guid:
                    return _reader.ReadGuid();
                case QType.Short:
                    return _reader.ReadInt16();
                case QType.Int:
                    return _reader.ReadInt32();
                case QType.Long:
                    return _reader.ReadInt64();
                case QType.Float:
                    return _reader.ReadSingle();
                case QType.Double:
                    return _reader.ReadDouble();
                case QType.Char:
                    return _reader.ReadChar();
                case QType.Timestamp:
                    return new QTimestamp(_reader.ReadInt64());
                case QType.Month:
                    return new QMonth(_reader.ReadInt32());
                case QType.Date:
                    return new QDate(_reader.ReadInt32());
                case QType.Datetime:
                    return new QDateTime(_reader.ReadDouble());
                case QType.Timespan:
                    return new QTimespan(_reader.ReadInt64());
                case QType.Minute:
                    return new QMinute(_reader.ReadInt32());
                case QType.Second:
                    return new QSecond(_reader.ReadInt32());
                case QType.Time:
                    return new QTime(_reader.ReadInt32());
            }

            throw new QReaderException("Unable to deserialize q atom of type: " + qtype);
        }
示例#55
0
        /// <summary>
        /// Dig a query
        /// </summary>
        /// <param name="name"></param>
        /// <param name="qtype"></param>
        /// <param name="qclass"></param>
        public void DigIt(string name, QType qtype, QClass qclass)
        {
            Message("; <<>> Dig.Net {0} <<>> @{1} {2} {3}", resolver.Version, resolver.DnsServer, qtype, name);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Response response = resolver.Query(name, qtype, qclass);
            sw.Stop();

            if (response.Error != "")
            {
                Message(";; " + response.Error);
                return;
            }

            PrintAnswer(response);

            Message(";; Query time: {0} msec", sw.ElapsedMilliseconds);
            Message(";; SERVER: {0}#{1}({2})", response.Server.Address, response.Server.Port, response.Server.Address);
            Message(";; WHEN: " + response.TimeStamp.ToString("ddd MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture));
            Message(";; MSG SIZE rcvd: " + response.MessageSize);
        }
示例#56
0
		public void DigIt(string name, QType qtype, QClass qclass)
		{
			Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
			Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US", false);

			Console.WriteLine("; <<>> Dig.Net {0} <<>> @{1} {2} {3}", resolver.Version, resolver.DnsServer, qtype, name);
			Console.WriteLine(";; global options: printcmd");

			Stopwatch sw = new Stopwatch();

			sw.Start();
			Response response = resolver.Query(name, qtype, qclass);
			sw.Stop();

			if(response.Error != "")
			{
				Console.WriteLine(";; " + response.Error);
				return;
			}

			Console.WriteLine(";; Got answer:");

			Console.WriteLine(";; ->>HEADER<<- opcode: {0}, status: {1}, id: {2}",
				response.header.OPCODE,
				response.header.RCODE,
				response.header.ID);
			Console.WriteLine(";; flags: {0}{1}{2}{3}; QUERY: {4}, ANSWER: {5}, AUTHORITY: {6}, ADDITIONAL: {7}",
				response.header.QR ? " qr" : "",
				response.header.AA ? " aa" : "",
				response.header.RD ? " rd" : "",
				response.header.RA ? " ra" : "",
				response.header.QDCOUNT,
				response.header.ANCOUNT,
				response.header.NSCOUNT,
				response.header.ARCOUNT);
			Console.WriteLine("");

			if (response.header.QDCOUNT > 0)
			{
				Console.WriteLine(";; QUESTION SECTION:");
				foreach (Question question in response.Questions)
					Console.WriteLine(";{0}" , question);
				Console.WriteLine("");
			}

			if (response.header.ANCOUNT > 0)
			{
				Console.WriteLine(";; ANSWER SECTION:");
				foreach (AnswerRR answerRR in response.Answers)
					Console.WriteLine(answerRR);
				Console.WriteLine("");
			}

			if (response.header.NSCOUNT > 0)
			{
				Console.WriteLine(";; AUTHORITY SECTION:");
				foreach (AuthorityRR authorityRR in response.Authorities)
					Console.WriteLine(authorityRR);
				Console.WriteLine("");
			}

			if (response.header.ARCOUNT > 0)
			{
				Console.WriteLine(";; ADDITIONAL SECTION:");
				foreach (AdditionalRR additionalRR in response.Additionals)
					Console.WriteLine(additionalRR);
				Console.WriteLine("");
			}

			Console.WriteLine(";; Query time: {0} msec", sw.ElapsedMilliseconds);
			Console.WriteLine(";; SERVER: {0}#{1}({2})" ,response.Server.Address,response.Server.Port,response.Server.Address);
			Console.WriteLine(";; WHEN: " + response.TimeStamp.ToString("ddd MMM dd HH:mm:ss yyyy",new System.Globalization.CultureInfo("en-US")));
			Console.WriteLine(";; MSG SIZE rcvd: " + response.MessageSize);
		}
示例#57
0
 /// <summary>
 ///  返回一个bool表达式
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="Property"></param>
 /// <param name="Data"></param>
 /// <param name="QueryType"></param>
 /// <returns></returns>
 public static Expression <Func <T, bool> > GetExpression <T>(string Property, object Data, QType QueryType)
 {
     return(Expsion.GetExpression <T>(Property, Data, QueryType));
 }
示例#58
0
        /// <summary>
        /// Performs a Trace on query
        /// </summary>
        /// <param name="name"></param>
        /// <param name="qtype"></param>
        /// <param name="qclass"></param>
        public void Trace(string name, QType qtype, QClass qclass)
        {
            Message("; <<>> DigTrace.Net {0} <<>> @{1} {2} {3}", resolver.Version, resolver.DnsServer, qtype, name);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            Message(";; Loading Root nameservers");
            var rootaddresses = resolver.LoadRootFile();

            foreach(var ra in rootaddresses)
            {
                //Message(";; Asking {0} ({1}) for nameserver for {2} ", ra.Key, ra.Value, name);
                var nsaddress = TraceNameservers(name, ra,qtype, qclass, true);
                if (nsaddress != null)
                {
                    Message(";; Using {0} as nameserver for {1}", nsaddress, name);
                    resolver.DnsServer = nsaddress.ToString();
                    break;
                }

            }

            Response response = resolver.Query(name, qtype, qclass);
            sw.Stop();

            if (response.Error != "")
            {
                Message(";; " + response.Error);
                return;
            }

            PrintAnswer(response);

            Message(";; Query time: {0} msec", sw.ElapsedMilliseconds);
            Message(";; SERVER: {0}#{1}({2})", response.Server.Address, response.Server.Port, response.Server.Address);
            Message(";; WHEN: " + response.TimeStamp.ToString("ddd MMM dd HH:mm:ss yyyy", CultureInfo.InvariantCulture));
            Message(";; MSG SIZE rcvd: " + response.MessageSize);
        }
示例#59
0
        /// <summary>
        /// Recursive tracing of nameservers
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parentNameserver"></param>
        /// <param name="qtype"></param>
        /// <param name="qclass"></param>
        /// <param name="firstOnly"></param>
        /// <returns></returns>
        private IPAddress TraceNameservers(string name, KeyValuePair<string, IPAddress> parentNameserver, QType qtype, QClass qclass, bool firstOnly)
        {
            Message(";; Asking {0} ({1}) for nameserver of {2} ", parentNameserver.Key, parentNameserver.Value, name);
            resolver.DnsServer = parentNameserver.Value.ToString();

            //preserving cache flag
            var saveuseCache = resolver.UseCache;
            resolver.UseCache = false;

            //performing a nameserver search
            Response nsresponse = resolver.Query(name, QType.NS, QClass.IN);

            //performing the requested search
            Response qresponse = resolver.Query(name, qtype, qclass);

            resolver.UseCache = saveuseCache;

            //sorting answers
            List<RecordNS> nameservers = new List<RecordNS>();
            List<RecordA> nameserveraddresses = new List<RecordA>();
            List<RecordAAAA> nameserveraddresV6 = new List<RecordAAAA>();

            foreach (var ans in nsresponse.Answers)
                SortAnswers(nameservers, nameserveraddresses, nameserveraddresV6, ans.RECORD);

            foreach (var ans in nsresponse.Authorities)
                SortAnswers(nameservers, nameserveraddresses, nameserveraddresV6, ans.RECORD);

            foreach (var ans in nsresponse.Additionals)
                SortAnswers(nameservers, nameserveraddresses, nameserveraddresV6, ans.RECORD);

            foreach (var ans in qresponse.Answers)
                SortAnswers(nameservers, nameserveraddresses, nameserveraddresV6, ans.RECORD);

            foreach (var ans in qresponse.Authorities)
                SortAnswers(nameservers, nameserveraddresses, nameserveraddresV6, ans.RECORD);

            foreach (var ans in qresponse.Additionals)
                SortAnswers(nameservers, nameserveraddresses, nameserveraddresV6, ans.RECORD);

            //if one of the nameservers is the calling nameserver, we've reached the end, return the IP of this nameserver
            //if there are answers (from the requested query) - we have the name server
            //if there are no more child nameservers - we reached the end, return the nameserver we did find and attempt a query on it.
            if ((nameservers.FirstOrDefault(i => i.NSDNAME == parentNameserver.Key) != null) || (qresponse.Answers.Count > 0) || (nameservers.Count == 0))
                return parentNameserver.Value;

            foreach (var ns in nameservers)
            {
                string nsname = ns.NSDNAME;
                var nsaddress = nameserveraddresses.Where(nsa => nsa.RR.NAME == nsname).Select(nsa=>nsa.Address).FirstOrDefault();
                if (nsaddress == null)
                    nsaddress = nameserveraddresV6.Where(nsa => nsa.RR.NAME == nsname).Select(nsa=>nsa.Address).FirstOrDefault();
                if (nsaddress == null)
                {
                    Message(";; nameserver {0} did not provide an address, attempting to resolve.",nsname);
                    //continue;
                    var hostentry = Dns.GetHostEntry(nsname);
                    if ((hostentry != null) && (hostentry.AddressList.Length > 0))
                    {
                        nsaddress = hostentry.AddressList[0];
                        Message(";; nameserver {0} extrnally resolved to {1}", nsname,nsaddress);

                    }
                    else
                    {
                        Message(";; nameserver {0} doesn't have an address and failed to resolve, skipping.", nsname);
                        continue;
                    }

                }
                var childns = TraceNameservers(name, new KeyValuePair<string, IPAddress>(nsname, nsaddress),qtype,qclass, firstOnly);

                if (childns != null)
                {
                    //reached the last NS.
                    return childns;
                }

            }
            return null;
        }
示例#60
0
文件: Question.cs 项目: sstraus/xmpp
 ///<summary>
 ///</summary>
 ///<param name="qName"></param>
 ///<param name="qType"></param>
 ///<param name="qClass"></param>
 public Question(string qName, QType qType, QClass qClass)
 {
     QName = qName;
     QType = qType;
     QClass = qClass;
 }