Example #1
0
        protected void TXTRecordCheck(DnsResourceRecord record, ref bool spfRecordExists)
        {
            if (spfRecordExists == false && record.ToString().Contains("spf"))
            {
                spfRecordExists = true;
            }

            WriteLineInvoke("Found TXT record " + record.ToString(), Color.Gainsboro);
            Invoke(new Finished(WriteEmptyLine));
        }
Example #2
0
        public static IEnumerable <string> ValueAsStrings(this DnsResourceRecord drr)
        {
            switch (drr)
            {
            case TxtRecord txt:
                return(txt.Text);

            default:
                return(new[] { drr.ToString() });
            }
        }
Example #3
0
        protected void ARecordCheck(DnsResourceRecord record, ARecord arecord)
        {
            bool online = false;
            bool acc80  = false;
            bool acc443 = false;

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

                if (arecord == null || arecord.Address == null)
                {
                    Invoke(new Finished(WriteEmptyLine));
                    return;
                }

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

                    UpdateStatusInvoke("Attempting to acess host on port 80...");
                    if (CanReachHost(arecord.Address, 80))
                    {
                        acc80 = true;
                    }

                    UpdateStatusInvoke("Attempting to acess host on port 443...");
                    if (CanReachHost(arecord.Address, 443))
                    {
                        acc443 = true;
                    }
                }

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

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

                    WriteStringInvoke("443 ", Color.Gainsboro);
                    if (acc443)
                    {
                        WriteLineInvoke("Open", Color.YellowGreen);
                    }
                    else
                    {
                        WriteLineInvoke("Closed", Color.OrangeRed);
                    }
                }

                Invoke(new Finished(WriteEmptyLine));
            }
        }
Example #4
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));
            }
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (runThread != null && runThread.IsAlive)
            {
                runThread.Abort();
                button1.Text = "Check";
                return;
            }

            string host        = Hostname;
            bool   checkA      = CheckARecords;
            bool   checkAAAA   = CheckAAAARecords;
            bool   checkMX     = CheckMXRecords;
            bool   checkTXT    = CheckTXTRecords;
            bool   checkSRV    = CheckSRVRecords;
            bool   checkPTR    = CheckPTRRecords;
            bool   validateSPF = ValidateSPFRecords;

            runThread = new Thread(new ThreadStart(delegate()
            {
                LookupClient lookupClient = new LookupClient();

                if (InvokeRequired)
                {
                    Invoke(new WriteString(WriteStringColor), new object[] { "Checking host ", richTextBox1.ForeColor });
                    Invoke(new WriteString(WriteLineColor), new object[] { host, Color.YellowGreen });
                    Invoke(new Finished(WriteEmptyLine));
                }

                if (checkA)
                {
                    var response = lookupClient.Query(host, QueryType.A);

                    if (response.HasError)
                    {
                        if (InvokeRequired)
                        {
                            WriteLineInvoke("Failed to retrieve A records for host", Color.OrangeRed);
                            Invoke(new Finished(WriteEmptyLine));
                        }
                    }
                    else
                    {
                        for (int i = 0; i < response.AllRecords.Count(); i++)
                        {
                            DnsResourceRecord record = response.AllRecords.ElementAt(i);
                            ARecord arecord          = null;

                            if (response.Answers.Count > i)
                            {
                                arecord = response.Answers.OfType <ARecord>().ElementAt(i);
                            }

                            ARecordCheck(record, arecord);
                        }
                    }
                }
                if (checkMX)
                {
                    var response = lookupClient.Query(host, QueryType.MX);

                    if (response.HasError)
                    {
                        if (InvokeRequired)
                        {
                            WriteLineInvoke("No MX records found for host", Color.Gainsboro);
                            Invoke(new Finished(WriteEmptyLine));
                        }
                    }
                    else
                    {
                        for (int i = 0; i < response.AllRecords.Count(); i++)
                        {
                            DnsResourceRecord record = response.AllRecords.ElementAt(i);
                            MxRecord mxrecord        = null;

                            if (response.Answers.Count > i)
                            {
                                mxrecord = response.Answers.OfType <MxRecord>().ElementAt(i);
                            }

                            MXRecordCheck(record, mxrecord);
                        }
                    }
                }
                if (checkTXT)
                {
                    var response = lookupClient.Query(host, QueryType.TXT);

                    if (response.HasError)
                    {
                        WriteLineInvoke("No TXT records found for host", Color.Gainsboro);
                        Invoke(new Finished(WriteEmptyLine));
                    }
                    else
                    {
                        bool foundSpfRecord = false;
                        bool spfIsValid     = false;

                        for (int i = 0; i < response.AllRecords.Count(); i++)
                        {
                            DnsResourceRecord record = response.AllRecords.ElementAt(i);
                            TxtRecord txtrecord      = null;

                            if (response.Answers.Count > i)
                            {
                                txtrecord = response.Answers.OfType <TxtRecord>().ElementAt(i);
                            }

                            TXTRecordCheck(record, ref foundSpfRecord);

                            if (record.ToString().Contains("spf1"))
                            {
                                spfIsValid = IsSPFValid(record.ToString());
                            }
                        }

                        if (!foundSpfRecord)
                        {
                            WriteLineInvoke("Warning: No SPF records found!", Color.OrangeRed);
                        }
                        else
                        {
                            if (!validateSPF)
                            {
                                WriteLineInvoke("Note: Use SPF Validation option to validate an SPF record", Color.Black);
                            }
                            else
                            {
                                if (spfIsValid)
                                {
                                    WriteLineInvoke("SPF exists and is valid", Color.YellowGreen);
                                }
                                else
                                {
                                    WriteLineInvoke("Warning: SPF exists, but doesn't appear valid", Color.OrangeRed);
                                }
                            }
                        }
                    }
                }

                if (InvokeRequired)
                {
                    Invoke(new Finished(DnsCheckComplete));
                    UpdateStatusInvoke("Ready");
                }
            }));
            runThread.Start();

            button1.Text = "Cancel";
        }