public void Parse(byte[] data, int offset)
        {
            while (offset < data.Length)
            {
                int         labelLen;
                MyDnsRecord RecordItem = new MyDnsRecord();
                RecordItem.Name = MyDns.GetLabelName(data, offset, out labelLen);
                offset         += labelLen;
                //
                offset++;
                RecordItem.QType = (QueryType)data[++offset];
                //
                offset++;
                RecordItem.QClass = (QueryClass)data[++offset];
                //
                offset++;
                RecordItem.TTL = data[offset++] * 256 * 256 * 256 + data[offset++] * 256 * 256 + data[offset++] * 256 + data[offset++];
                //
                RecordItem.RDLength = data[offset++] * 256 + data[offset++];
                //
                switch (RecordItem.QType)
                {
                case QueryType.A:
                    RecordItem.RDDate = new A_RR(data, offset, RecordItem.RDLength);
                    break;

                case QueryType.CNAME:
                    RecordItem.RDDate = new CNAME_RR(data, offset, RecordItem.RDLength);
                    break;

                case QueryType.MX:
                    RecordItem.RDDate = new MX_RR(data, offset, RecordItem.RDLength);
                    break;

                case QueryType.NS:
                    RecordItem.RDDate = new NS_RR(data, offset, RecordItem.RDLength);
                    break;

                case QueryType.SOA:
                    RecordItem.RDDate = new SOA_RR(data, offset, RecordItem.RDLength);
                    break;

                case QueryType.TXT:
                    RecordItem.RDDate = new TXT_RR(data, offset, RecordItem.RDLength);
                    break;
                }
                Records.Add(RecordItem);
                offset += RecordItem.RDLength;
            }
        }
Beispiel #2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            Type myenum = typeof(QueryType);
            Array ar= Enum.GetValues(myenum);
           QueryType qtype=  (QueryType ) ar.GetValue(cbType.SelectedIndex);
            MyDns mydns = new MyDns();
            if (!mydns.Search(txtDomain.Text.Trim(), qtype, txtDns.Text.Trim(), null ))
            {

                MessageBox.Show(mydns.header.RCODE.ToString());
                return;
            }
            txtInfo.Clear();
            txtInfo.AppendText (string.Format ("回复记录数:{0}\n",mydns.header.ANCOUNT) );
            txtInfo.AppendText(string.Format("回复额外记录数:{0}\n", mydns.header.ARCOUNT ));
            txtInfo.AppendText(string.Format("回复权威记录数:{0}", mydns.header.NSCOUNT ));

            txtContent.Clear();
            foreach (MyDnsRecord item in mydns.record.Records)
            {
                txtContent.AppendText(item.QType.ToString() + "   " + item.RDDate.ToString()+"\n");
            }
        }