Beispiel #1
0
        private static void CanChangeCircuit()
        {
            var       requestUri = "http://icanhazip.com/";
            IPAddress torIp;
            IPAddress changedIp;

            // 1. Get TOR IP
            using (var socksPortClient = new SocksPort.Client(HostAddress, SocksPort))
            {
                var handler = socksPortClient.GetHandlerFromDomain("icanhazip.com");
                using (var httpClient = new HttpClient(handler))
                {
                    var content = httpClient.GetAsync(requestUri).Result.Content.ReadAsStringAsync().Result;
                    var gotIp   = IPAddress.TryParse(content.Replace("\n", ""), out torIp);
                    Assert.True(gotIp);
                }

                // 2. Change TOR IP
                var controlPortClient = new ControlPort.Client(HostAddress, ControlPort, ControlPortPassword);
                controlPortClient.ChangeCircuit();

                // 3. Get changed TOR IP
                handler = socksPortClient.GetHandlerFromRequestUri(requestUri);
                using (var httpClient = new HttpClient(handler))
                {
                    var content = httpClient.GetAsync(requestUri).Result.Content.ReadAsStringAsync().Result;
                    var gotIp   = IPAddress.TryParse(content.Replace("\n", ""), out changedIp);
                    Assert.True(gotIp);
                }
            }

            Assert.NotEqual(changedIp, torIp);
        }
Beispiel #2
0
        private static void RequestWith3Ip()
        {
            var requestUri = "http://icanhazip.com/";

            // 1. Get real IP
            using (var httpClient = new HttpClient())
            {
                var content = httpClient.GetAsync(requestUri).Result.Content.ReadAsStringAsync().Result;
                Console.WriteLine($"Your real IP: \t\t{content}");
            }

            // 2. Get TOR IP
            using (var socksPortClient = new SocksPort.Client())
            {
                var handler = socksPortClient.GetHandlerFromDomain("icanhazip.com");
                using (var httpClient = new HttpClient(handler))
                {
                    var content = httpClient.GetAsync(requestUri).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine($"Your TOR IP: \t\t{ content}");
                }

                // 3. Change TOR IP
                var controlPortClient = new ControlPort.Client(password: "******");
                controlPortClient.ChangeCircuit();

                // 4. Get changed TOR IP
                handler = socksPortClient.GetHandlerFromRequestUri(requestUri);
                using (var httpClient = new HttpClient(handler))
                {
                    var content = httpClient.GetAsync(requestUri).Result.Content.ReadAsStringAsync().Result;
                    Console.WriteLine($"Your other TOR IP: \t{content}");
                }
            }
        }
Beispiel #3
0
        private static void TorIpIsNotTheRealOne()
        {
            var       requestUri = "http://icanhazip.com/";
            IPAddress realIp;
            IPAddress torIp;

            // 1. Get real IP
            using (var httpClient = new HttpClient())
            {
                var content = httpClient.GetAsync(requestUri).Result.Content.ReadAsStringAsync().Result;
                var gotIp   = IPAddress.TryParse(content.Replace("\n", ""), out realIp);
                Assert.True(gotIp);
            }

            // 2. Get TOR IP
            using (var socksPortClient = new SocksPort.Client(HostAddress, SocksPort))
            {
                var handler = socksPortClient.GetHandlerFromDomain("icanhazip.com");
                using (var httpClient = new HttpClient(handler))
                {
                    var content = httpClient.GetAsync(requestUri).Result.Content.ReadAsStringAsync().Result;
                    var gotIp   = IPAddress.TryParse(content.Replace("\n", ""), out torIp);
                    Assert.True(gotIp);
                }
            }

            Assert.NotEqual(realIp, torIp);
        }