示例#1
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();
                    }
                }
            }
        }
示例#2
0
        public async void TestConnectByIPv4Async()
        {
            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 = await socks.ConnectAsync(host, 80, 10 * 1000);

                socket.Disconnect(false);
            } catch (TimeoutException) {
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
示例#3
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));
        }
示例#4
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);
     }
 }
示例#5
0
 public void Should_pass_through_river_over_fiddler()
 {
     using (var riverServer = new RiverServer(4550))
         using (var server = new SocksServerToRiverClient(4549, "localhost:8888"))
             using (var socks = new Socks4Client("localhost", 4549, "httpbin.org", 80))
             {
                 TestConnction(socks);
             }
 }
示例#6
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);
         }
     }
 }
示例#7
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();
                }
            }
        }
示例#8
0
        public async Task TestTimeoutException()
        {
            using (var proxy = new Socks4ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

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

                try {
                    stream = await socks.ConnectAsync("example.com", 25, 1000);
                } catch (TimeoutException) {
                    Assert.Pass();
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    stream?.Dispose();
                }
            }
        }
示例#9
0
        public async Task TestConnectByDomainAsync()
        {
            using (var proxy = new Socks4ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

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

                try {
                    stream = await socks.ConnectAsync("www.google.com", 80, ConnectTimeout);
                } catch (TimeoutException) {
                    Assert.Inconclusive("Timed out.");
                } catch (Exception ex) {
                    Assert.Fail(ex.Message);
                } finally {
                    stream?.Dispose();
                }
            }
        }
示例#10
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();
                }
            }
        }
示例#11
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();
                }
            }
        }
示例#12
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);
                }
            }
        }
示例#13
0
        public void TestConnectByDomain()
        {
            using (var proxy = new Socks4ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks4Client(proxy.IPAddress.ToString(), proxy.Port);
                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();
                    }
                }
            }
        }
示例#14
0
 public void TestInit()
 {
     _socksClient = new Socks4Client("127.0.0.1", 301, "127.0.0.1", 79);
 }
示例#15
0
        public void TestConnectByDomainAsync()
        {
            var socks = new Socks4Client("100.39.36.100", 58288, new NetworkCredential("", ""));

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