Esempio n. 1
0
        private static async Task SocksExampleAsync(int torSocksPort)
        {
            // Tor support SOCKS 4, 4A, and 5
            var socksEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), torSocksPort);
            var socks5Client = new Socks5Client();
            var socket = socks5Client.ConnectToServer(socksEndpoint);
            socket = socks5Client.ConnectToDestination(socket, "icanhazip.com", 80);

            using (var proxiedStream = new NetworkStream(socket))
            using (var writer = new StreamWriter(proxiedStream))
            using (var reader = new StreamReader(proxiedStream))
            {
                writer.WriteLine("GET / HTTP/1.1");
                writer.WriteLine("Host: icanhazip.com");
                writer.WriteLine();
                writer.Flush();

                Console.WriteLine((await reader.ReadToEndAsync()).Trim());
            }
        }
Esempio n. 2
0
        private static async Task HttpSocksExampleAsync(int torSocksPort)
        {
            // Tor support SOCKS 4, 4A, and 5
            var socksEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), torSocksPort);
            var socks5Client = new Socks5Client();
            var socket = socks5Client.ConnectToServer(socksEndpoint);
            socket = socks5Client.ConnectToDestination(socket, "icanhazip.com", 443);

            using (var httpClient = new HttpClient(new NetworkHandler(socket)))
            using (var response = await httpClient.GetAsync("https://icanhazip.com/"))
            {
                Console.WriteLine("{0} {1}", (int)response.StatusCode, response.ReasonPhrase);
                Console.WriteLine((await response.Content.ReadAsStringAsync()).Trim());
            }
        }