Example #1
0
        private static async Task MainAsync()
        {
            // configure
            var settings = new TorSharpSettings
            {
                ZippedToolsDirectory    = Path.Combine(Path.GetTempPath(), "TorZipped"),
                ExtractedToolsDirectory = Path.Combine(Path.GetTempPath(), "TorExtracted"),
                PrivoxyPort             = 1337,
                TorSocksPort            = 1338,
                TorControlPort          = 1339,
                TorControlPassword      = "******",
                ToolRunnerType          = ToolRunnerType.VirtualDesktop,
                WaitForTestEndpoint     = true
            };

            // download tools
            await new TorSharpToolFetcher(settings, new HttpClient()).FetchAsync();

            // execute
            using (var proxy = new TorSharpProxy(settings))
                using (var handler = proxy.CreateHttpClientHandler())
                    using (var httpClient = new HttpClient(handler))
                    {
                        await proxy.ConfigureAndStartAsync();

                        Console.WriteLine(await httpClient.GetStringAsync("http://icanhazip.com"));

                        await proxy.GetNewIdentityAsync();

                        Console.WriteLine(await httpClient.GetStringAsync("http://icanhazip.com"));
                    }
        }
Example #2
0
        public static async Task <string> MakeTorRequest(string url)
        {
            string result = String.Empty;

            using (var proxy = new TorSharpProxy(_torSettings))
                using (var handler = proxy.CreateHttpClientHandler())
                    using (var httpClient = new HttpClient(handler))
                    {
                        await proxy.ConfigureAndStartAsync();

                        result = await httpClient.GetStringAsync(url);
                    }

            return(result);
        }