Пример #1
0
        public void TestConnectByIPv4()
        {
            var    socks  = new Socks4Client("100.39.36.100", 58288);
            var    host   = "74.125.197.99";        // ResolveIPv4 ("www.google.com");
            Socket socket = null;

            if (host == null)
            {
                return;
            }

            try {
                socket = socks.Connect(host, 80, 10 * 1000);
                socket.Disconnect(false);
            } catch (TimeoutException) {
                Assert.Inconclusive("Timed out.");
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Пример #2
0
        public void TestConnectByIPv4()
        {
            using (var proxy = new Socks4ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks4Client(proxy.IPAddress.ToString(), proxy.Port);
                var    host   = "74.125.197.99";            // ResolveIPv4 ("www.google.com");
                Socket socket = null;

                if (host == null)
                {
                    return;
                }

                try {
                    socket = socks.Connect(host, 80, ConnectTimeout);
                    socket.Disconnect(false);
                } catch (TimeoutException) {
                    Assert.Inconclusive("Timed out.");
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    if (socket != null)
                    {
                        socket.Dispose();
                    }
                }
            }
        }
Пример #3
0
 public void Should_take_data_from_test_server_via_proxy4a_dns()
 {
     using (var socks = new Socks4Client())
     {
         socks.Connect(ProxyServerName, ProxyServerPort, "httpbin.org", 80, true);
         TestConnction(socks);
     }
 }
Пример #4
0
        public void TestArgumentExceptions()
        {
            var credentials = new NetworkCredential("user", "password");
            var socks       = new Socks4Client("socks4.proxy.com", 0, credentials);

            Assert.Throws <ArgumentNullException> (() => new Socks4Client(null, 1080));
            Assert.Throws <ArgumentException> (() => new Socks4Client(string.Empty, 1080));
            Assert.Throws <ArgumentOutOfRangeException> (() => new Socks4Client(socks.ProxyHost, -1));
            Assert.Throws <ArgumentNullException> (() => new Socks4Client(socks.ProxyHost, 1080, null));

            Assert.AreEqual(4, socks.SocksVersion);
            Assert.AreEqual(1080, socks.ProxyPort);
            Assert.AreEqual("socks4.proxy.com", socks.ProxyHost);
            Assert.AreEqual(credentials, socks.ProxyCredentials);

            Assert.Throws <ArgumentNullException> (() => socks.Connect(null, 80));
            Assert.Throws <ArgumentNullException> (() => socks.Connect(null, 80, ConnectTimeout));
            Assert.Throws <ArgumentNullException> (async() => await socks.ConnectAsync(null, 80));
            Assert.Throws <ArgumentNullException> (async() => await socks.ConnectAsync(null, 80, ConnectTimeout));

            Assert.Throws <ArgumentException> (() => socks.Connect(string.Empty, 80));
            Assert.Throws <ArgumentException> (() => socks.Connect(string.Empty, 80, ConnectTimeout));
            Assert.Throws <ArgumentException> (async() => await socks.ConnectAsync(string.Empty, 80));
            Assert.Throws <ArgumentException> (async() => await socks.ConnectAsync(string.Empty, 80, ConnectTimeout));

            Assert.Throws <ArgumentOutOfRangeException> (() => socks.Connect("www.google.com", 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => socks.Connect("www.google.com", 0, ConnectTimeout));
            Assert.Throws <ArgumentOutOfRangeException> (async() => await socks.ConnectAsync("www.google.com", 0));
            Assert.Throws <ArgumentOutOfRangeException> (async() => await socks.ConnectAsync("www.google.com", 0, ConnectTimeout));

            Assert.Throws <ArgumentOutOfRangeException> (() => socks.Connect("www.google.com", 80, -ConnectTimeout));
            Assert.Throws <ArgumentOutOfRangeException> (async() => await socks.ConnectAsync("www.google.com", 80, -ConnectTimeout));
        }
Пример #5
0
 public void Should_take_data_from_test_server_via_proxy4a_on_river_socks_server()
 {
     using (var server = new SocksProxyServer(4546))
     {
         using (var socks = new Socks4Client())
         {
             socks.Connect("localhost", 4546, "httpbin.org", 80, true);
             TestConnction(socks);
         }
     }
 }
Пример #6
0
        public void TestConnectByIPv4()
        {
            var    socks  = new Socks4Client("100.39.36.100", 58288, new NetworkCredential("", ""));
            var    host   = ResolveIPv4("www.google.com");
            Socket socket = null;

            try {
                socket = socks.Connect(host, 80, 10 * 1000);
                socket.Disconnect(false);
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Пример #7
0
        public void TestConnectByDomain()
        {
            using (var proxy = new Socks4ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks4Client(proxy.IPAddress.ToString(), proxy.Port);
                Stream stream = null;

                try {
                    stream = socks.Connect("www.google.com", 80, ConnectTimeout);
                } catch (TimeoutException) {
                    Assert.Inconclusive("Timed out.");
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    stream?.Dispose();
                }
            }
        }
Пример #8
0
        public void TestConnectByDomain()
        {
            var    socks  = new Socks4Client("100.39.36.100", 58288);
            Socket socket = null;

            try {
                socket = socks.Connect("www.google.com", 80, 10 * 1000);
                socket.Disconnect(false);
            } catch (TimeoutException) {
                Assert.Inconclusive("Timed out.");
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Пример #9
0
        public void TestConnectByDomain()
        {
            // Note: this Socks4 proxy does not support the Socks4a protocol
            var    socks  = new Socks4Client("100.39.36.100", 58288);
            Socket socket = null;

            try {
                socket = socks.Connect("www.google.com", 80, 10 * 1000);
                socket.Disconnect(false);
            } catch (ProxyProtocolException) {
                // This is expected since this proxy does not support Socks4a
            } catch (TimeoutException) {
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Пример #10
0
        public void Should_compare_direct_and_proxy_response()
        {
            string direct;

            using (var cli = new TcpClient())
            {
                cli.Connect("httpbin.org", 80);
                direct = TestConnction(cli.GetStream());
                direct = Regex.Replace(direct, "(?im)^Date: .*$", "");
                File.WriteAllText(Path.GetTempFileName(), direct);
            }
            using (var server = new SocksProxyServer(4547))
            {
                using (var socks = new Socks4Client())
                {
                    socks.Connect("localhost", 4547, "httpbin.org", 80, true);
                    var proxifyed = TestConnction(socks);
                    proxifyed = Regex.Replace(proxifyed, "(?im)^Date: .*$", "");
                    File.WriteAllText(Path.GetTempFileName(), proxifyed);
                    Assert.AreEqual(direct, proxifyed);
                }
            }
        }
Пример #11
0
        public void TestConnectByDomain()
        {
            var socks = new Socks4Client("100.39.36.100", 58288, new NetworkCredential("", ""));

            Assert.Throws <ProxyProtocolException> (() => socks.Connect("www.google.com", 80, 10 * 1000));
        }