public DnsMessage(byte[] data) { Timestamp = DateTime.Now; DnsReader byteReader = new DnsReader(data); // Header Header = new Header(byteReader); // Question, Answer, Authority, Additional Counts Questions = new Question[this.QuestionRecordCount]; Answers = new Answer[this.AnswerRecordCount]; Authorities = new Authority[this.AuthorityRecordCount]; Additionals = new Additional[this.AdditionalRecordCount]; // Read Records for (int i = 0; i < this.QuestionRecordCount; i++) { this.Questions[i] = new Question(byteReader); } for (int i = 0; i < this.AnswerRecordCount; i++) { this.Answers[i] = new Answer(byteReader); } for (int i = 0; i < this.AuthorityRecordCount; i++) { this.Authorities[i] = new Authority(byteReader); } for (int i = 0; i < this.AdditionalRecordCount; i++) { this.Additionals[i] = new Additional(byteReader); } }
public DnsMessage() { Timestamp = DateTime.Now; Header = new Header(); Header.TransactionId = (ushort)RANDOM.Next(ushort.MaxValue); Header.QR = false; Header.OperationCode = OperationCode.Query; Questions = new Question[0]; Answers = new Answer[0]; Authorities = new Authority[0]; Additionals = new Additional[0]; }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine(" DNS PACKET"); sb.AppendLine(string.Concat(" Message Timestamp : ", this.Timestamp.ToLocalTime().ToString())); sb.AppendLine(string.Concat(" Transaction Id (ID) : ", this.TransactionId.ToHexString("0x"))); sb.AppendLine(string.Concat(" Is Query (RQ) : ", this.IsQuery.ToString())); sb.AppendLine(string.Concat(" Operation Code (Opcode) : ", this.OperationCode.ToString())); sb.AppendLine(string.Concat(" Is Authoritive Answer (AA) : ", this.IsAuthoritiveAnswer.ToString())); sb.AppendLine(string.Concat(" Is Truncated (TC) : ", this.IsTruncated.ToString())); sb.AppendLine(string.Concat(" Is Recursion Desired (RD) : ", this.IsRecursionDesired.ToString())); sb.AppendLine(string.Concat(" Is Recursion Available (RA) : ", this.IsRecursionAvailable.ToString())); sb.AppendLine(string.Concat(" Response Code (RCODE) : ", this.ResponseCode.ToString())); sb.AppendLine(string.Concat(" Question Count (QDCOUNT) : ", this.QuestionRecordCount.ToString())); foreach (Question question in this.Questions) { Question record = question as Question; if (record != null) { sb.AppendLine(string.Concat(" -Question Record (Name) : ", record.Domain.ToString())); sb.AppendLine(string.Concat(" -Class : ", record.Class.ToString())); sb.AppendLine(string.Concat(" -Type : ", record.Type.ToString())); } } sb.AppendLine(string.Concat(" Answer Count (ANCOUNT) : ", this.AnswerRecordCount.ToString())); foreach (Answer answer in this.Answers) { Answer record = answer as Answer; if (record != null) { sb.AppendLine(string.Concat(" -Answer Record (Name) : ", record.Domain.ToString())); sb.AppendLine(string.Concat(" -Class : ", record.Class.ToString())); sb.AppendLine(string.Concat(" -Type : ", record.Type.ToString())); sb.AppendLine(string.Concat(" -Ttl : ", record.Ttl.ToString())); sb.AppendLine(string.Concat(" -Record : ", record.Record.ToString())); } } sb.AppendLine(string.Concat(" Additional Count (ARCOUNT) : ", this.AdditionalRecordCount.ToString())); foreach (Additional additional in this.Additionals) { Additional record = additional as Additional; if (record != null) { sb.AppendLine(string.Concat(" -Additional Record (Name) : ", record.Domain.ToString())); sb.AppendLine(string.Concat(" -Class : ", record.Class.ToString())); sb.AppendLine(string.Concat(" -Type : ", record.Type.ToString())); sb.AppendLine(string.Concat(" -Ttl : ", record.Ttl.ToString())); sb.AppendLine(string.Concat(" -Record : ", record.Record.ToString())); } } sb.AppendLine(string.Concat(" Authority Count (NACOUNT) : ", this.AuthorityRecordCount.ToString())); foreach (Authority authority in this.Authorities) { Authority record = authority as Authority; if (record != null) { sb.AppendLine(string.Concat(" -Authority Record (Name) : ", record.Domain.ToString())); sb.AppendLine(string.Concat(" -Class : ", record.Class.ToString())); sb.AppendLine(string.Concat(" -Type : ", record.Type.ToString())); sb.AppendLine(string.Concat(" -Ttl : ", record.Ttl.ToString())); sb.AppendLine(string.Concat(" -Record : ", record.Record.ToString())); } } sb.AppendLine(); return(sb.ToString()); }