Ejemplo n.º 1
0
        private byte[] dataGram(string domainName,SendBy sendBy)
        {
            string[] dName = domainName.Split('.');
            uint dgLength = (uint)sendBy * 2;
            uint bodyLength;
            dGramHeader dHead = new dGramHeader();
            dHead.ID = 0;
            dHead.QR = 0;
            dHead.OpCode = OpCodes.QUERY;
            dHead.AA = 0;
            dHead.TC = 0;
            dHead.RD = 1;
            dHead.RA = 0;
            dHead.Z = 0;
            dHead.RCode = RCodes.Success;
            dHead.QDCount = 1;
            dHead.ANCount = 0;
            dHead.NSCount = 0;
            dHead.ARCount = 0;

            byte[] header = formHeader(dHead);
            byte[] question = formQuestion(dName);
            bodyLength = (uint)(header.Length + question.Length);

            byte[] dGram = new byte[dgLength + bodyLength];
            int ptr = 0;
            if (sendBy == SendBy.TCP)
            {
                dGram[0] = (byte)((bodyLength >> 8) & 0xFF);
                dGram[1] = (byte)(bodyLength & 0xFF);
                ptr = 2;
            }
            for (int n = 0; n < header.Length; n++)
            {
                dGram[ptr] = header[n];
                ptr += 1;
            }
            for (int m = 0; m < question.Length; m++)
            {
                dGram[ptr] = question[m];
                ptr += 1;
            }
            return dGram;
        }
Ejemplo n.º 2
0
 private int getResults(Byte[] receiveBytes, SendBy sendBy)
 {
     int ptr = ((int)sendBy * 2);
     int response = (int)receiveBytes[ptr + 2] & 0x80;
     int authoritativeAnswer = (int)receiveBytes[ptr + 2] & 0x04;
     int truncation = (int)receiveBytes[ptr + 2] & 0x02;
     int rcode = (int)receiveBytes[ptr + 3] & 0x0f;
     int exists = ((int)receiveBytes[ptr + 6] << 8) + (int)receiveBytes[ptr + 7];
     int result;
     if (response == 0)
     {
         result = -8;
     }
     else if (rcode == 1)
     {
         result = -1;
     }
     else if (rcode == 2)
     {
         result = -2;
     }
     else if (rcode == 3)
     {
         result = -3;
     }
     else if (rcode == 5)
     {
         result = -5;
     }
     else
     {
         result = exists;
     }
     return result;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Searches for TLD.
 /// </summary>
 /// <param name="domainName"></param>
 /// <param name="sendBy">UDP or TCP</param>
 public Lookup(string domainName, SendBy sendBy)
 {
     this.domainName = domainName;
     this.sendBy = sendBy;
     send();
 }