public void Should_socks4_have_a_ctor_with_proxy_and_host() { var server = new DemoTcpServer(); var proxyPort = GetFreePort(); var proxy = new SocksServer("socks://0.0.0.0:" + proxyPort); var proxyClient = new Socks4ClientStream("127.0.0.1", proxyPort, "127.0.0.1", server.Port); var data = new byte[] { 1, 2, 3, 4 }; proxyClient.Write(data); var buf = new byte[16 * 1024]; var d = proxyClient.Read(buf, 0, buf.Length); Assert.AreEqual(4, d, "Should read 4 bytes in a single packet"); // demo server is XOR 37 CollectionAssert.AreEqual(data.Select(x => (byte)(x ^ 37)).ToArray(), buf.Take(d).ToArray()); server.Dispose(); proxy.Dispose(); proxyClient.Dispose(); }
// [Timeout(5000)] public void Should_chain_3_socks() { _ = typeof(Socks4ClientStream); // to load the type var port1 = GetFreePort(); var proxy1 = new SocksServer(new ServerConfig { EndPoints = { new IPEndPoint(IPAddress.Loopback, port1), new IPEndPoint(IPAddress.IPv6Loopback, port1), }, }); var port2 = GetFreePort(); var proxy2 = new SocksServer(new ServerConfig { EndPoints = { new IPEndPoint(IPAddress.Loopback, port2), new IPEndPoint(IPAddress.IPv6Loopback, port2), }, }); var port3 = GetFreePort(); var proxy3 = new SocksServer(new ServerConfig { EndPoints = { new IPEndPoint(IPAddress.Loopback, port3), new IPEndPoint(IPAddress.IPv6Loopback, port3), }, }); var port0 = GetFreePort(); var proxy = new SocksServer(new ServerConfig { EndPoints = { new IPEndPoint(IPAddress.Loopback, port0), new IPEndPoint(IPAddress.IPv6Loopback, port0), }, }) { Chain = { "socks4://127.0.0.1:" + port1, // "socks4://127.0.0.1:" + port2, // "socks4://127.0.0.1:" + port3, }, }; var cli = new Socks4ClientStream("localhost", port0, "www.google.com", 80); TestConnction(cli, "www.google.com"); cli.Dispose(); proxy1.Dispose(); proxy2.Dispose(); proxy3.Dispose(); proxy.Dispose(); }