Ejemplo n.º 1
0
        private static void StartDNServer(
            IEnumerable <IPAddress> upDns, ushort upDnsPort,
            IEnumerable <IPAddress> pureDns, ushort pureDnsPort,
            int udpListenerCount, int tcpListenerCount,
            IPAddress upEcs, IPAddress pureEcs,
            IEnumerable <string> list, IPEndPoint bindIpPoint, int timeout = 10000)
        {
            var server = new ConditionalForwardingDnsServer(bindIpPoint, udpListenerCount, tcpListenerCount)
            {
                PureDns     = new DnsClient(pureDns, timeout, pureDnsPort),
                UpStreamDns = new DnsClient(upDns, timeout, upDnsPort),
                Timeout     = timeout,
                BanAny      = BanAny
            };

            if (pureEcs != null)
            {
                server.PureEcs = new ClientSubnetOption(32, pureEcs);
            }
            if (upEcs != null)
            {
                server.UpStreamEcs = new ClientSubnetOption(32, upEcs);
            }

            server.LoadDomains(list);
            server.ExceptionThrown += async(sender, e) =>
            {
                await Task.Run(() =>
                {
                    Console.WriteLine(Verbose ? $@"Errored: {e.Exception}" : $@"Errored: {e.Exception.Message}");
                });
            };
            server.Start();
        }
Ejemplo n.º 2
0
        private static void StartDNServer(
            IEnumerable <IPAddress> upDns, ushort upDnsPort,
            IEnumerable <IPAddress> pureDns, ushort pureDnsPort,
            int udpListenerCount, int tcpListenerCount,
            IPAddress upEcs, IPAddress pureEcs,
            IEnumerable <string> list, IPEndPoint bindIpPoint, int timeout = 10000)
        {
            var server = new ConditionalForwardingDnsServer(bindIpPoint, udpListenerCount, tcpListenerCount)
            {
                PureDns     = new DnsClient(pureDns, timeout, pureDnsPort),
                UpStreamDns = new DnsClient(upDns, timeout, upDnsPort),
                Timeout     = timeout,
            };

            if (pureEcs != null)
            {
                server.PureEcs = new ClientSubnetOption(32, pureEcs);
            }
            if (upEcs != null)
            {
                server.UpStreamEcs = new ClientSubnetOption(32, upEcs);
            }

            server.LoadDomains(list);
            if (Verbose)
            {
                server.ClientConnected += (sender, e) =>
                {
                    return(Task.Run(() =>
                    {
                        Console.WriteLine($@"{e.RemoteEndpoint} Connected: {e.ProtocolType}");
                    }));
                };
            }
            server.ExceptionThrown += (sender, e) =>
            {
                return(Task.Run(() =>
                {
                    Console.WriteLine($@"Errored: {e.Exception}");
                }));
            };
            server.Start();
        }