Exemple #1
0
        public static DnsResponse Lookup(DnsRequest request, IPAddress dnsServer = null)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (dnsServer == null)
            {
                dnsServer = GetDnsServer();
            }

            IPEndPoint server = new IPEndPoint(dnsServer, _dnsPort);

            byte[] requestMessage  = request.GetMessage();
            byte[] responseMessage = UdpTransfer(server, requestMessage);

            return(new DnsResponse(responseMessage));
        }
Exemple #2
0
        public static MXRecord[] MXLookup(string domain, IPAddress dnsServer = null)
        {
            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }

            DnsRequest request = new DnsRequest();

            request.AddQuestion(new DnsQuestion(domain, DnsType.MX, DnsClass.IN));
            DnsResponse response = Lookup(request, dnsServer);

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

            return(response.Answers
                   .Where(a => a.Record is MXRecord)
                   .Select(a => a.Record as MXRecord)
                   .ToArray());
        }