public RequestResolver(string dnsServerAddress, string responsiblePerson, TldCollection tldCollection)
        {
            if (!tldCollection.IsReady)
            {
                throw new ArgumentException("TLD collection is not ready.", nameof(tldCollection));
            }

            dnsServerAddress = dnsServerAddress.ToLower();

            _requestDomainSuffix     = '.' + dnsServerAddress;
            _dnsServerDomain         = new Domain(dnsServerAddress);
            _responsiblePersonDomain = new Domain(responsiblePerson);
            _serial = DateTime.UtcNow.Ticks;

            _tldCollection = tldCollection;
        }
예제 #2
0
        private static void Main(string[] args)
        {
            WriteHeader();

            var tldCollection = new TldCollection();

            Console.Write("Fetching TLD list...");

            while (!tldCollection.IsReady)
            {
                Thread.Sleep(100);
            }

            Console.WriteLine($"success ({tldCollection.Count} items).");
            Console.WriteLine();

            bool logRequests     = false;
            var  requestResolver = new RequestResolver("httpcheck.singulink.com", "admin.singulink.com", tldCollection);

            requestResolver.AddPermanentRecord("singulink.com", true);

            requestResolver.RequestReceived += (s, e) => {
                if (logRequests)
                {
                    var now = DateTime.Now;
                    Console.WriteLine($"{now.ToShortDateString()} {now.ToShortTimeString()} REQ {e.Id} {e.RequestDomain} {e.EmailDomain}");
                }
            };

            requestResolver.ResponseSent += (s, e) => {
                if (logRequests)
                {
                    var now = DateTime.Now;
                    Console.WriteLine($"{now.ToShortDateString()} {now.ToShortTimeString()} RES {e.Id} {e.RequestDomain} {e.Result} {(int)e.Ttl.TotalSeconds}");
                }
            };

            var dnsServer = new DnsServer(requestResolver);

            RunDnsServer(dnsServer);

            Console.WriteLine("DNS Server started. Press D to toggle debug, C to clear window, or X to exit.");

            while (true)
            {
                var key = Console.ReadKey(true);

                if (key.Key == ConsoleKey.D)
                {
                    logRequests = !logRequests;
                    Console.WriteLine($"Request logging: {logRequests}");
                }
                else if (key.Key == ConsoleKey.C)
                {
                    Console.Clear();
                    WriteHeader();
                }
                else if (key.Key == ConsoleKey.X)
                {
                    break;
                }
            }

            Console.Write("Shutting down DNS Server...");

            dnsServer.Dispose();
            tldCollection.Dispose();

            Thread.Sleep(1000);

            Console.WriteLine("done.");
        }