public async Task TestConnectSocks4ByDomainAsync() { using (var proxy = new Socks4ProxyListener()) { proxy.Start(IPAddress.Loopback, 0); var socks = new Socks4aClient(proxy.IPAddress.ToString(), proxy.Port); Socket socket = null; try { socket = await socks.ConnectAsync("www.google.com", 80); socket.Disconnect(false); Assert.Fail("Sending a domain to a SOCKS4-only proxy server should have failed."); } catch (ProxyProtocolException) { // This is expected since this proxy does not support Socks4a Assert.Pass($"{socks.ProxyHost} does not support Socks4a."); } catch (TimeoutException) { Assert.Inconclusive("Timed out."); } catch (Exception ex) { Assert.Fail(ex.Message); } finally { if (socket != null) { socket.Dispose(); } } } }
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(); } } } }
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(); } } }
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(); } } }
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(); } } } }