Пример #1
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();
                }
            }
        }
Пример #2
0
        public async Task TestConnectByIPv4Async()
        {
            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 = await socks.ConnectAsync(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 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 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();
                }
            }
        }
Пример #5
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();
                }
            }
        }
Пример #6
0
        public async void TestConnectByIPv4Async()
        {
            var    socks  = new Socks4Client("100.39.36.100", 58288, new NetworkCredential("", ""));
            var    host   = ResolveIPv4("www.google.com");
            Socket socket = null;

            try {
                socket = await socks.ConnectAsync(host, 80, 10 * 1000);

                socket.Disconnect(false);
            } catch (Exception ex) {
                Assert.Fail(ex.Message);
            } finally {
                if (socket != null)
                {
                    socket.Dispose();
                }
            }
        }
Пример #7
0
        public async void TestConnectByDomainAsync()
        {
            var    socks  = new Socks4Client("100.39.36.100", 58288);
            Socket socket = null;

            try {
                socket = await socks.ConnectAsync("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();
                }
            }
        }
Пример #8
0
        public async void TestConnectByDomainAsync()
        {
            // Note: this Socks4 proxy does not support the Socks4a protocol
            var    socks  = new Socks4Client("100.39.36.100", 58288);
            Socket socket = null;

            try {
                socket = await socks.ConnectAsync("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();
                }
            }
        }
Пример #9
0
        public async void TestConnectByDomainAsync()
        {
            using (var proxy = new Socks4ProxyListener()) {
                proxy.Start(IPAddress.Loopback, 0);

                var    socks  = new Socks4Client(proxy.IPAddress.ToString(), proxy.Port);
                Socket socket = null;

                try {
                    socket = await socks.ConnectAsync("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();
                    }
                }
            }
        }
Пример #10
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));
        }