Exemple #1
0
        public string[] GetMXRecords(string domain)
        {
            IntPtr   ptr1 = IntPtr.Zero;
            IntPtr   ptr2 = IntPtr.Zero;
            MXRecord recMx;

            if (Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                throw new NotSupportedException();
            }
            ArrayList list1 = new ArrayList();
            int       num1  = DnsMx.DnsQuery(ref domain, QueryTypes.DNS_TYPE_MX, QueryOptions.DNS_QUERY_BYPASS_CACHE, 0, ref ptr1, 0);

            if (num1 != 0)
            {
                throw new Win32Exception(num1);
            }
            for (ptr2 = ptr1; !ptr2.Equals(IntPtr.Zero); ptr2 = recMx.pNext)
            {
                recMx = (MXRecord)Marshal.PtrToStructure(ptr2, typeof(MXRecord));
                if (recMx.wType == 15)
                {
                    string text1 = Marshal.PtrToStringAuto(recMx.pNameExchange);
                    list1.Add(text1);
                }
            }
            DnsMx.DnsRecordListFree(ptr1, 0);
            return((string[])list1.ToArray(typeof(string)));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            string strHostName = Dns.GetHostName();

            Console.WriteLine("Local Machine's Host Name: " + strHostName);


            DnsMx mx = new DnsMx();

            string[] hosts = mx.GetMXRecords("breakermind.com");
            foreach (var host in hosts)
            {
                Console.WriteLine(host);
                IPAddress[] ips = Dns.GetHostAddresses(host);
                foreach (IPAddress ip in ips)
                {
                    Console.WriteLine("    {0}", ip);
                }
                Console.ReadKey();
            }
        }