Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            bool printResultsAfterwards = true;

            DACConsoleSession session = new DACConsoleSession(DACSettings.GetDefaultSettings());

            Console.WriteLine("Starting...");
            DACSessionResult result = session.Start();

            if (printResultsAfterwards)
            {
                if (result.AvailableDomains != null)
                {
                    Console.WriteLine("\nAvailable domains:");
                    foreach (string domain in result.AvailableDomains)
                    {
                        Console.WriteLine(domain);
                    }
                }
                if (result.UnavailableDomains != null)
                {
                    Console.WriteLine("\nUnavailable domains:");
                    foreach (string domain in result.UnavailableDomains)
                    {
                        Console.WriteLine(domain);
                    }
                }
                if (result.ErroneousDomains != null)
                {
                    Console.WriteLine("\nErroneous domains:");
                    foreach (string domain in result.ErroneousDomains)
                    {
                        Console.WriteLine(domain);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public DACSessionResult Start()
        {
            if (settings == null)
            {
                throw new NoSettingsException("Settings can not be null when a session is started.");
            }

            DACSessionResult result         = new DACSessionResult();
            List <string>    availDomains   = new List <string>();
            List <string>    unavailDomains = new List <string>();
            List <string>    erroDomains    = new List <string>();

            string[] tlds = TLDs();

            result.SessionStarted = DateTime.Now;


            Console.WriteLine(settings.Introduction);
            bool stop = false;

            while (!stop)
            {
                string line = Console.ReadLine();

                if (line.Trim().Equals(""))
                {
                    stop = true;
                }
                else if (line.Contains(".") && !line.StartsWith(".") && !line.EndsWith("."))
                {
                    if (!HasValidTLD(tlds, line))
                    {
                        Console.WriteLine(settings.ErroneousDomainText);
                        if (!erroDomains.Contains(line))
                        {
                            erroDomains.Add(line);
                        }
                        if (settings.PrintErrors)
                        {
                            Console.WriteLine("Invalid top-level domain");
                        }
                        continue;
                    }

                    IPHostEntry entry;
                    try
                    {
                        entry = Dns.GetHostEntry(line);
                        if (entry != null)
                        {
                            Console.WriteLine(settings.DomainUnavailableText);
                            if (!unavailDomains.Contains(line))
                            {
                                unavailDomains.Add(line);
                            }
                        }
                        else
                        {
                            Console.WriteLine(settings.DomainAvailableText);
                            if (!availDomains.Contains(line))
                            {
                                availDomains.Add(line);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Equals("No such host is known"))
                        {
                            Console.WriteLine(settings.DomainAvailableText);
                            if (!availDomains.Contains(line))
                            {
                                availDomains.Add(line);
                            }
                        }
                        else
                        {
                            Console.WriteLine(settings.ErroneousDomainText);
                            if (!erroDomains.Contains(line))
                            {
                                erroDomains.Add(line);
                            }
                            if (settings.PrintErrors)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }

            Console.WriteLine(settings.FinishText);
            if (availDomains.Count > 0)
            {
                result.AvailableDomains = availDomains.ToArray();
            }

            if (unavailDomains.Count > 0)
            {
                result.UnavailableDomains = unavailDomains.ToArray();
            }

            if (erroDomains.Count > 0)
            {
                result.ErroneousDomains = erroDomains.ToArray();
            }

            result.SessionFinished = DateTime.Now;
            return(result);
        }