Esempio n. 1
0
        protected EmailServerStatus CheckEmailServer(string host, int port)
        {
            EmailServerStatus ess = new EmailServerStatus();

            if (CanPingHost(host))
            {
                ess.Online = true;
            }
            else
            {
                ess.Online = false;
                return(ess);
            }

            using (TcpClient client = new TcpClient())
            {
                client.Connect(host, port);

                if (client.Connected)
                {
                    ess.Open = true;

                    using (NetworkStream stream = client.GetStream())
                    {
                        if (SendCommand(stream, "EHLO dnscheck.localhost"))
                        {
                            if (SendCommand(stream, "MAIL FROM: [email protected]"))
                            {
                                if (SendCommand(stream, "RCPT TO: [email protected]"))
                                {
                                    ess.AllowsRelay = true;
                                    SendCommand(stream, "QUIT");
                                }
                            }
                        }
                        stream.Close();
                    }
                }
            }

            return(ess);
        }
Esempio n. 2
0
        protected void MXRecordCheck(DnsResourceRecord record, MxRecord mxrecord)
        {
            bool online      = false;
            bool acc25       = false;
            bool acc465      = false;
            bool acc587      = false;
            bool allowsRelay = false;

            if (InvokeRequired)
            {
                WriteLineInvoke("Found MX record " + record.ToString(), Color.Gainsboro);

                if (mxrecord == null || mxrecord.Exchange == null)
                {
                    Invoke(new Finished(WriteEmptyLine));
                    return;
                }

                UpdateStatusInvoke("Attempting to ping host " + mxrecord.Exchange);
                if (CanPingHost(mxrecord.Exchange))
                {
                    online = true;

                    UpdateStatusInvoke("Attempting to acess host on port 25...");
                    if (CanReachHost(mxrecord.Exchange, 25))
                    {
                        acc25 = true;
                    }

                    UpdateStatusInvoke("Attempting to acess host on port 465...");
                    if (CanReachHost(mxrecord.Exchange, 465))
                    {
                        acc465 = true;
                    }

                    UpdateStatusInvoke("Attempting to acess host on port 587...");
                    if (CanReachHost(mxrecord.Exchange, 587))
                    {
                        acc587 = true;
                    }

                    if (acc25)
                    {
                        UpdateStatusInvoke("Attempting to communicate using SMTP on port 25...");
                        EmailServerStatus ess = CheckEmailServer(mxrecord.Exchange, 25);

                        if (ess.AllowsRelay)
                        {
                            allowsRelay = true;
                        }
                    }
                }

                if (!online)
                {
                    WriteLineInvoke("Host appears offline!", Color.OrangeRed);
                }
                else
                {
                    WriteStringInvoke("Host online! ", Color.YellowGreen);

                    WriteStringInvoke("25 ", Color.Gainsboro);

                    if (acc25)
                    {
                        WriteStringInvoke("Open ", Color.YellowGreen);
                    }
                    else
                    {
                        WriteStringInvoke("Closed ", Color.OrangeRed);
                    }

                    WriteStringInvoke("465 ", Color.Gainsboro);

                    if (acc465)
                    {
                        WriteStringInvoke("Open ", Color.YellowGreen);
                    }
                    else
                    {
                        WriteStringInvoke("Closed ", Color.OrangeRed);
                    }

                    WriteStringInvoke("587 ", Color.Gainsboro);

                    if (acc587)
                    {
                        WriteLineInvoke("Open", Color.YellowGreen);
                    }
                    else
                    {
                        WriteLineInvoke("Closed", Color.OrangeRed);
                    }

                    if (allowsRelay)
                    {
                        WriteLineInvoke("Warning: Host allows relaying!", Color.OrangeRed);
                    }
                }

                Invoke(new Finished(WriteEmptyLine));
            }
        }