Exemplo n.º 1
0
        static void Main(string[] args)
        {
            using (var dnsServer = new DnsServer(IPAddress.Any, 10, 10))
            {
                DNSEncoder.Init();
                var client     = new QuicClient();
                var connection = client.Connect("127.0.0.1", 11000);
                var stream     = connection.CreateStream(QuickNet.Utilities.StreamType.ClientBidirectional);
                async Task OnDnsServerOnQueryReceived(object sender, QueryReceivedEventArgs e)
                {
                    if (!(e.Query is DnsMessage query))
                    {
                        return;
                    }
                    await Task.Run(() =>
                    {
                        stream.Send(DNSEncoder.Encode(query));
                        e.Response = DnsMessage.Parse(stream.Receive());
                    });
                }

                dnsServer.QueryReceived += OnDnsServerOnQueryReceived;
                dnsServer.Start();
                Console.WriteLine(@"-------ARASHI Q DNS------");
                Console.WriteLine(@"-------DOTNET ALPHA------");

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(@"ArashiDNS Server Running");

                Console.WriteLine(@"Press any key to stop dns server");
                Console.WriteLine("------------------------");
                Console.ReadLine();
                Console.WriteLine("------------------------");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            DNSEncoder.Init();
            var listener = new QuicListener(11000);

            listener.Start();
            while (true)
            {
                var client = listener.AcceptQuicClient();

                client.OnDataReceived += c => {
                    var msg = c.Data;
                    using (var bgWorker = new BackgroundWorker())
                    {
                        bgWorker.DoWork += (sender, eventArgs) =>
                        {
                            var dnsQMsg = DnsMessage.Parse(msg);
                            var dnsRMsg =
                                new DnsClient(IPAddress.Parse("8.8.8.8"), 1000).SendMessage(dnsQMsg);
                            c.Send(DNSEncoder.Encode(dnsRMsg));

                            Console.ForegroundColor = ConsoleColor.Cyan;
                            dnsQMsg.Questions.ForEach(o => Console.WriteLine("Qu:" + o));
                            Console.ForegroundColor = ConsoleColor.Green;
                            dnsRMsg.AnswerRecords.ForEach(o => Console.WriteLine("An:" + o));
                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                            dnsRMsg.AuthorityRecords.ForEach(o => Console.WriteLine("Au:" + o));
                            Console.ForegroundColor = ConsoleColor.Green;
                        };
                        bgWorker.RunWorkerAsync();
                    }
                };
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            DNSEncoder.Init();
            var server = new WebSocketServer("ws://0.0.0.0:3030");

            server.ListenerSocket.NoDelay = true;
            server.Start(ws =>
            {
                ws.OnOpen   = () => Console.WriteLine(ws.ConnectionInfo.ClientIpAddress + ":Open!");
                ws.OnClose  = () => Console.WriteLine(ws.ConnectionInfo.ClientIpAddress + ":Close!");
                ws.OnBinary = msg =>
                {
                    using (var bgWorker = new BackgroundWorker())
                    {
                        bgWorker.DoWork += (sender, eventArgs) =>
                        {
                            var dnsQMsg = DnsMessage.Parse(msg);
                            var dnsRMsg =
                                new DnsClient(IPAddress.Parse("8.8.8.8"), 1000).SendMessage(dnsQMsg);
                            ws.Send(DNSEncoder.Encode(dnsRMsg));

                            Console.ForegroundColor = ConsoleColor.Cyan;
                            dnsQMsg.Questions.ForEach(o => Console.WriteLine("Qu:" + o));
                            Console.ForegroundColor = ConsoleColor.Green;
                            dnsRMsg.AnswerRecords.ForEach(o => Console.WriteLine("An:" + o));
                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                            dnsRMsg.AuthorityRecords.ForEach(o => Console.WriteLine("Au:" + o));
                            Console.ForegroundColor = ConsoleColor.Green;
                        };
                        bgWorker.RunWorkerAsync();
                    }
                };
            });

            Console.ReadLine();
        }