コード例 #1
0
ファイル: Program.cs プロジェクト: vasili8m/DnsLibs
        public static void Main(string[] args)
        {
            string redirectorAppExecutablePath = Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory,
                REDIRECTOR_EXECUTABLE_RELATIVE_PATH);
            bool isRedirectorExist = File.Exists(redirectorAppExecutablePath);

            try
            {
                m_LogProvider = new ColoredConsoleLogProvider();
                LogProvider.SetCurrentLogProvider(m_LogProvider);

#if LOG_TO_FILE
                ConsoleToFileRedirector.Start("Logs");
#endif
                m_DnsApi = DnsApi.Instance;
                m_DnsApi.InitLogger(LogLevel.Debug);
                DnsProxySettings dnsProxySettings = CreateDnsProxySettings();
                IDnsProxyServerCallbackConfiguration dnsProxyServerCallbackConfiguration =
                    new DnsProxyServerCallbackConfiguration();

                int dnsProxyProcessId = Process.GetCurrentProcess().Id;
                if (isRedirectorExist)
                {
                    m_CoreProcess =
                        WindowsTools.CreateProcess(
                            redirectorAppExecutablePath,
                            string.Format("{0} {1}", dnsProxyProcessId, DNS_PROXY_PORT),
                            true);
                    m_CoreProcess.Start();
                }

                m_DnsApi.StartDnsFiltering(new DnsApiConfiguration
                {
                    IsEnabled        = true,
                    DnsProxySettings = dnsProxySettings,
                    DnsProxyServerCallbackConfiguration = dnsProxyServerCallbackConfiguration
                });

                Console.ReadLine();
            }
            finally
            {
                m_DnsApi.StopDnsFiltering();
                if (isRedirectorExist && m_CoreProcess != null)
                {
                    m_CoreProcess.StandardInput.WriteLine("Switching off the core sample app...");
                    m_CoreProcess.Kill();
#if UNINSTALL_REDIRECT_DRIVER
                    UninstallRedirectDriver();
#endif
                }

                ConsoleToFileRedirector.Stop();
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            string redirectorAppExecutablePath = Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory,
                REDIRECTOR_EXECUTABLE_RELATIVE_PATH);
            bool isRedirectorExist = File.Exists(redirectorAppExecutablePath);

            try
            {
#if LOG_TO_FILE
                ConsoleToFileRedirector.Start("Logs");
#endif
                DnsSimpleApi.StartLogger();
                DnsProxySettings dnsProxySettings = CreateDnsProxySettings();
                IDnsProxyServerCallbackConfiguration dnsProxyServerCallbackConfiguration =
                    new DnsProxyServerCallbackConfiguration();
                int dnsProxyProcessId = Process.GetCurrentProcess().Id;
                if (isRedirectorExist)
                {
                    m_CoreProcess =
                        WindowsTools.CreateProcess(
                            redirectorAppExecutablePath,
                            $"{dnsProxyProcessId} {DNS_PROXY_PORT}",
                            true);
                    m_CoreProcess.Start();
                }

                dnsProxySettings.OptimisticCache = true;
                dnsProxySettings.EnableDNSSECOK  = true;

                DnsSimpleApi.StartDnsFiltering(new DnsApiConfiguration
                {
                    IsEnabled        = true,
                    DnsProxySettings = dnsProxySettings,
                    DnsProxyServerCallbackConfiguration = dnsProxyServerCallbackConfiguration
                });

                Console.ReadLine();
            }
            finally
            {
                DnsSimpleApi.StopDnsFiltering();
                if (isRedirectorExist && m_CoreProcess != null)
                {
                    m_CoreProcess.StandardInput.WriteLine("Switching off the core sample app...");
                    m_CoreProcess.Kill();
#if UNINSTALL_REDIRECT_DRIVER
                    UninstallRedirectDriver();
#endif
                }

                ConsoleToFileRedirector.Stop();
            }
        }