Exemplo n.º 1
0
        private static void BindListener(string ipAddressForBinding)
        {
            IPAddress ip;

            if (!IPAddress.TryParse(ipAddressForBinding, out ip))
            {
                return;
            }

            if (Servers.ContainsKey(ipAddressForBinding))
            {
                return;
            }

            var dnsServer = new DnsServer(ip, 10, 10);

            dnsServer.QueryReceived += OnQueryReceived;
            Servers.Add(ipAddressForBinding, dnsServer);
            dnsServer.Start();

            var appLog = new System.Diagnostics.EventLog {
                Source = "Hyper-V Dns Proxy"
            };

            appLog.WriteEntry($"Started DNS Service on {ipAddressForBinding}");
        }
Exemplo n.º 2
0
        private void SettingButton_Click(object sender, RoutedEventArgs e)
        {
            var settingsWindow = new SettingsWindow();

            settingsWindow.Closed += (a, s) =>
            {
                IsLog.IsChecked    = DnsSettings.DebugLog;
                IsGlobal.IsChecked = Equals(DnsSettings.ListenIp, IPAddress.Any);

                if (!Equals(DnsSettings.ListenIp, IPAddress.Any) &&
                    !Equals(DnsSettings.ListenIp, IPAddress.Loopback) &&
                    MyTools.PortIsUse(DnsSettings.ListenPort))
                {
                    MDnsServer.Stop();
                    MDnsServer = new DnsServer(new IPEndPoint(DnsSettings.ListenIp, DnsSettings.ListenPort), 10, 10);
                    MDnsServer.QueryReceived += QueryResolve.ServerOnQueryReceived;
                    Snackbar.MessageQueue.Enqueue(new TextBlock {
                        Text = $"监听地址 : [{DnsSettings.ListenIp}]"
                    });
                    MDnsSvrTask = new Task(() => MDnsServer.Start());
                    MDnsSvrTask.Start();
                    IsGlobal.ToolTip = $"当前监听 : [{DnsSettings.ListenIp}]";
                }

                //IsLog.ToolTip = IsLog.IsChecked.Value ? "记录日志 : 是" : "记录日志 : 否";
                //IsGlobal.ToolTip = Equals(DnsSettings.ListenIp, IPAddress.Any) ? "当前监听 : 局域网" : "当前监听 : 本地";
            };
            settingsWindow.Show();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            dc         = new OrangeDNSDataContext();
            updateTime = int.Parse(dc.GeneralSettings.SingleOrDefault(s => s.Name == "UpdateTime").Value);
            mainDns    = dc.GeneralSettings.SingleOrDefault(s => s.Name == "MainDns").Value;
            Timer updateData = new Timer(TimerCallback, null, 0, updateTime);

            using (DnsServer server = new DnsServer(System.Net.IPAddress.Any, 10, 10))
            {
                server.QueryReceived += OnQueryReceived;
                server.Start();
                while (true)
                {
                    string input = Console.ReadLine();
                    switch (input)
                    {
                    case "exit":
                        return;

                    case "update":
                        TimerCallback(null);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 启动本地DNS服务
 /// </summary>
 /// <param name="i">是否显示右下角提示,1提示,不填不提示</param>
 private void StartServer(int i = 0)
 {
     SendLog("开始启动DNS服务...");
     if (isRun)
     {
         SendLog("服务已运行");
         if (i == 1)
         {
             SendNotify("服务已运行");
         }
     }
     else
     {
         server.QueryReceived += OnQueryReceived;
         try
         {
             server.Start();
             SendLog("启动成功,服务开始运行");
             if (i == 1)
             {
                 SendNotify("启动成功,服务开始运行");
             }
             this.isRun = true;
             SetStatus();
         }
         catch (Exception ex)
         {
             SendLog("启动失败!错误:" + ex.Message);
             if (i == 1)
             {
                 SendNotify("启动失败!错误:" + ex.Message);
             }
         }
     }
 }
Exemplo n.º 5
0
        public void Start()
        {
            GetProcessors();

            server_ = new DnsServer(IPAddress.Any, state_.Config.Dns.UdpListeners, state_.Config.Dns.TcpListeners, ProcessDnsQuery);
            server_.Start();
        }
Exemplo n.º 6
0
 private void btn_start_Click(object sender, EventArgs e)
 {
     try
     {
         if (isDnsServerRunning)
         {
             Application.Exit();
             isDnsServerRunning = false;
             server.Stop();
             btn_start.BackColor = System.Drawing.Color.DarkRed;
             btn_start.Text      = "Start DNS Server";
             tbxResult.AppendText("Server stopped successfully.\n");
         }
         else
         {
             server = new DnsServer(IPAddress.Any, 100, 100, ProcessQuery);
             server.ExceptionThrown += server_ExceptionThrown;
             server.InvalidSignedMessageReceived += server_InvalidSignedMessageReceived;
             server.Start();
             isDnsServerRunning  = true;
             btn_start.BackColor = System.Drawing.Color.DarkGreen;
             btn_start.Text      = "Stop DNS Server";
             tbxResult.AppendText("Server started successfully.\n");
         }
     }
     catch (Exception ex)
     {
         tbxResult.AppendText("ERROR #1: " + ex.Message + "\n");
     }
 }
Exemplo n.º 7
0
        public static void Start_Dns_Server()
        {
            Global.Print("Dns Server Started.");
            DnsServer.QueryReceived += DnsServer_QueryReceived;

            DnsServer.Start();
        }
Exemplo n.º 8
0
        public async static Task InitAsync(int port = 53)
        {
            DnsRecords dnsRecords = new DnsRecords();

            _server = new DnsServer(dnsRecords);

            //添加映射记录
            dnsRecords.AddIPAddressResourceRecord("yswenli.net", "127.0.0.1");

            _server.OnRequested += (sender, e) =>
            {
                Console.WriteLine("[DNSServer Requested]: {0}", e.Request);
            };

            _server.OnResponded += (sender, e) =>
            {
                Console.WriteLine("[DNSServer Responded]: {0} => {1}", e.Request, e.Response);
            };

            _server.OnErrored += (sender, e) =>
            {
                Console.WriteLine("[DNSServer Errored]: {0}", e.Exception.Message);
            };

            _server.OnListening += async(sender, e) =>
            {
                Console.WriteLine("[DNSServer Listening]");

                //await new DnsClient("127.0.0.1").Lookup("yswenli.net");
            };

            //启动dns服务
            await _server.Start(port);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("FunDns.exe secondlevel.tld <acmeChallenge>");
                Console.WriteLine("--> Responds to 127-0-0-1.secondlevel.tld with 127.0.0.1");
                Console.WriteLine("--> If an acmeChallenge is provided, it replies to ALL txt requests with this.");
                return;
            }

            Console.WriteLine("Main domain name: " + args[0]);
            Search = args[0].ToLowerInvariant().Split('.');

            if (args.Length > 1)
            {
                AcmeChallenge = args[1];
            }


            var dnsServer = new DnsServer(IPAddress.Any, 8, 8);

            dnsServer.QueryReceived += DnsServer_QueryReceived;
            dnsServer.Start();

            Task.WaitAll(Task.Delay(-1)); // deliberately returning -1
        }
Exemplo n.º 10
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.º 11
0
        /// <summary>
        /// 启动DNS服务器
        /// </summary>
        public void Run()
        {
            StartHttpServer();
            DnsServer dnsServer = new DnsServer(MaxConnection, MaxConnection);

            dnsServer.QueryReceived += DnsServer_QueryReceived;
            dnsServer.Start();
        }
 public void Start(string endDnsIp, string serverIp, string redirectRecord)
 {
     _endDnsIp       = endDnsIp;
     _serverIp       = serverIp;
     _redirectRecord = redirectRecord;
     _server         = new DnsServer(IPAddress.Any, 10, 10, ProcessQuery);
     _server.Start();
 }
        public DnsServer Run()
        {
            var server = new DnsServer(System.Net.IPAddress.Any, 1, 1);

            server.QueryReceived += OnQueryReceived;
            server.Start();
            return(server);
        }
Exemplo n.º 14
0
        public void Run()
        {
            DNS = new DnsServer(new IPEndPoint(LocalIp, LocalProt), 8, 8);
            DNS.QueryReceived += QueryResolve.ServerOnQueryReceived;
            var bgw = new BackgroundWorker();

            bgw.DoWork += (o, args) => DNS.Start();
            bgw.RunWorkerAsync();
            Running = true;
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            var       maxConnection = 100;
            DnsServer dnsServer     = new DnsServer(maxConnection, maxConnection);

            dnsServer.QueryReceived += DnsServer_QueryReceived;
            dnsServer.Start();

            Console.Read();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            using (DnsServer server = new DnsServer(IPAddress.Any, 10, 10, ProcessQuery))
            {
                server.Start();

                Console.WriteLine("Press any key to stop server");
                Console.ReadLine();
            }
        }
Exemplo n.º 17
0
 static void Main(string[] args)
 {
     using (DnsServer server = new DnsServer(System.Net.IPAddress.Any, 10, 10))
     {
         server.QueryReceived += OnQueryReceived;
         server.Start();
         Console.WriteLine("Press any key to stop server");
         Console.ReadLine();
     }
 }
Exemplo n.º 18
0
        public static void Start()
        {
            DnsMessage msg = new DnsMessage();

            DnsServer server = new DnsServer(new IPEndPoint(ConfigMgr.dnsHost, ConfigMgr.dnsPort), 10, 10);

            server.QueryReceived += handleQuery;
            server.Start();
            return;
        }
Exemplo n.º 19
0
        public async Task Start()
        {
            await LoadBlacklist();

            LogToConsole($"Blacklisted domains: {_blacklistedUrls.Count}");

            _client = new DnsClient(IPAddress.Parse("1.1.1.1"), 200);

            _server = new DnsServer(10, 10);
            _server.QueryReceived += ServerOnQueryReceived;
            _server.Start();
        }
Exemplo n.º 20
0
        } // End Function OnQueryReceived

        public static void Test()
        {
            using (DnsServer server = new DnsServer(10, 10))
            {
                server.QueryReceived += OnQueryReceived;

                server.Start();

                Console.WriteLine("Press any key to stop server");
                System.Console.ReadKey();
            } // End Using server
        }     // End Sub Test
Exemplo n.º 21
0
        public static void Test()
        {
            using (DnsServer server = new DnsServer(IPAddress.Any, 10, 10))
            {
                server.ClientConnected += OnClientConnected;
                server.QueryReceived   += OnQueryReceived;

                server.Start();

                Console.WriteLine("Press any key to stop server");
                Console.ReadLine();
            } // End Using server
        }     // End Sub Test
Exemplo n.º 22
0
        public void Start()
        {
            var configFile = Assembly.GetEntryAssembly().Location;

            configFile = Path.Combine(Path.GetDirectoryName(configFile), "dns.config.xml");
            var config = DnsConfig.LoadFromXmlFile(configFile);

            _dnsManager = new DnsManager(config);

            _dnsServer = new DnsServer(10, 10);
            _dnsServer.QueryReceived += OnQueryReceived;
            _dnsServer.Start();
        }
Exemplo n.º 23
0
 private void DnsEnable_Checked(object sender, RoutedEventArgs e)
 {
     MDnsSvrTask = new Task(() => MDnsServer.Start());
     MDnsSvrTask.Start();
     if (!MDnsSvrTask.IsCompleted)
     {
         Snackbar.MessageQueue.Enqueue(new TextBlock()
         {
             Text = "DNS 服务器已启动"
         });
         TaskbarToolTip.Text = @"AuroraDNS - Running";
     }
 }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            DnsServer svr = new DnsServer(new IPEndPoint(IPAddress.Any, 54), 256, 0);

            svr.Start();

            svr.QueryReceived += Svr_QueryReceived;

            Console.Write(">");
            Console.ReadLine();

            svr.Stop();
        }
Exemplo n.º 25
0
 protected void startDnsServer()
 {
     try
     {
         DnsServer server = new DnsServer(System.Net.IPAddress.Any, 10, 10, onDnsQuery);
         this.AddListItem("Started DNS proxy...");
         server.ExceptionThrown += dnsServer_ExceptionThrown;
         server.Start();
     }
     catch (Exception e)
     {
         this.AddListItem(String.Format("ERROR STARTING DNS SERVER: {0}", e.Message));
     }
 }
Exemplo n.º 26
0
 public bool Start()
 {
     try
     {
         _server.Start();
         Logging.WriteVerbose("DNS Server started");
         return(true);
     }
     catch
     {
         Logging.WriteVerbose("Can not start DNS Server");
         return(false);
     }
 }
Exemplo n.º 27
0
        public override bool Run()
        {
            if (!DumpFolder.Exists)
            {
                return(false);
            }

            DnsServer server = new DnsServer(LocalAddress, 10, 10, ProcessQuery);

            server.Start();

            CreateJob(server);
            return(true);
        }
Exemplo n.º 28
0
        public void RunConsole()
        {
            m_log.WriteLine("[*] mod0 Umleitung - Starting DNS Masquerading Server.");

            using (DnsServer server = new DnsServer(IPAddress.Any, 10, 10))
            {
                server.QueryReceived += OnQueryReceived;

                server.Start();
                this.IsRunning = true;
                m_log.WriteLine("Press any key to stop server");
                Console.ReadLine();
            }
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            using (DnsServer server = new DnsServer(IPAddress.Any, 4, 1))
            {
                server.ClientConnected += OnClientConnected;
                server.QueryReceived   += OnQueryReceived;

                server.Start();

                Application.Run();

                //Console.WriteLine("Press any key to stop server");
                //Console.ReadLine();
            }
        }
Exemplo n.º 30
0
 private void IsGlobal_Unchecked(object sender, RoutedEventArgs e)
 {
     if (MyTools.PortIsUse(DnsSettings.ListenPort))
     {
         MDnsServer.Stop();
         MDnsServer = new DnsServer(new IPEndPoint(IPAddress.Loopback, DnsSettings.ListenPort), 10, 10);
         MDnsServer.QueryReceived += QueryResolve.ServerOnQueryReceived;
         Snackbar.MessageQueue.Enqueue(new TextBlock {
             Text = "监听地址 : 本地 " + IPAddress.Loopback
         });
         MDnsSvrTask = new Task(() => MDnsServer.Start());
         MDnsSvrTask.Start();
         IsGlobal.ToolTip = "当前监听 : 本地";
     }
 }