Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        private static void UninstallRedirectDriver()
        {
            string coreToolsExecutablePath = Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory,
                CORE_TOOLS_EXECUTABLE_RELATIVE_PATH);
            Process coreToolsProcess = WindowsTools.CreateProcess(
                coreToolsExecutablePath,
                ARG_DRV_UNINSTALL, true);

            coreToolsProcess.Start();
        }
Esempio n. 3
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();
            }
        }