public void DnsQuestionResponseParseTest()
        {
            var        msgBytes  = Convert.FromBase64String(ATypeQueryResponseTestData);
            DnsMessage msg       = DnsMessageParser.Parse(msgBytes);
            var        converted = DnsMessageParser.GetBytes(msg);

            byte[] msgNumsPart     = new byte[12];
            byte[] msgByteNumsPart = new byte[12];

            Buffer.BlockCopy(converted, 0, msgNumsPart, 0, 12);
            Buffer.BlockCopy(msgBytes, 0, msgByteNumsPart, 0, 12);

            Assert.IsTrue(msgNumsPart.SequenceEqual(msgByteNumsPart), $"{string.Join( ", ", msgNumsPart )} does not equal {string.Join( ", ", msgByteNumsPart )}");

            Assert.AreEqual <int>(msgBytes.Length, converted.Length, "Lengths are not equal");

            Assert.IsTrue(msgBytes.SequenceEqual(converted));
        }
Пример #2
0
        private DnsMessage SendQueryToFirstAvailable(List <IPAddress> dnsAddresses, DnsMessage query)
        {
            using (UdpClient client = new UdpClient(_clientPortNum, AddressFamily.InterNetwork)) {
                var dgram = DnsMessageParser.GetBytes(query);
                foreach (var address in dnsAddresses)
                {
                    IPEndPoint dnsEp = new IPEndPoint(address, 53);
                    client.Send(dgram, dgram.Length, dnsEp);
                    var responce = DnsMessageParser.Parse(client.Receive(ref dnsEp));
                    if (responce.IsResponse && responce.AnswerRecords.Count > 0)
                    {
                        return(responce);
                    }
                }
            }

            return(null);
        }