public void Check_socks_by_river4_client() { // default null var cli = new Socks4ClientStream("rt.xkip.ru", 11080, host, 80).Track(this); TestConnction(cli, host); // v4a force dns cli = new Socks4ClientStream("rt.xkip.ru", 11080, host, 80, proxyDns: true).Track(this); TestConnction(cli, host); // v4 force ip cli = new Socks4ClientStream("rt.xkip.ru", 11080, host, 80, proxyDns: false).Track(this); TestConnction(cli, host); // IPv4 - native support var ip = Dns.GetHostAddresses(host) .FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork); cli = new Socks4ClientStream("rt.xkip.ru", 11080, ip.ToString(), 80).Track(this); TestConnction(cli, host); cli = new Socks4ClientStream("rt.xkip.ru", 11080, ip.ToString(), 80, proxyDns: true).Track(this); TestConnction(cli, host); cli = new Socks4ClientStream("rt.xkip.ru", 11080, ip.ToString(), 80, proxyDns: false).Track(this); TestConnction(cli, host); // IPv6 - support via v4a host name /* * // my servers's ISP also is not supporting ipv6 * var ip6 = Dns.GetHostAddresses(host) * .FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetworkV6); * * cli = new Socks4ClientStream("rt.xkip.ru", 11080, ip6.ToString(), 80); * TestConnction(cli, host); * * cli = new Socks4ClientStream("rt.xkip.ru", 11080, ip6.ToString(), 80, proxyDns: true); * TestConnction(cli, host); * * cli = new Socks4ClientStream("rt.xkip.ru", 11080, ip6.ToString(), 80, proxyDns: false); * TestConnction(cli, host); */ }
static void Main2() { /* * var cli = new TcpClient("httpbin.org", 80); * var stream = cli.GetStream2(); */ var step1 = new Socks4ClientStream(); step1.Plug("127.0.0.1", 1080); step1.Route("127.0.0.1", 1081); var step2 = new Socks4ClientStream(step1, "127.0.0.1", 1082); var step3 = new Socks4ClientStream(step2, "httpbin.org", 80); var stream = step3; void read() { var buf = new byte[16 * 1024]; var c = stream.Read(buf, 0, buf.Length); if (c > 0) { var str = Encoding.UTF8.GetString(buf, 0, c); Console.WriteLine(str); // Console.WriteLine("\r\n==========<< " + c); Task.Run(delegate { read(); }); } } Task.Run(delegate { read(); }); var buf2 = Encoding.ASCII.GetBytes("GET /\r\n\r\n"); stream.Write(buf2, 0, buf2.Length); Console.ReadLine(); }
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(); }
static void MainClient() { var client = new Socks4ClientStream("127.0.0.1", 1080, "www.google.com", 80); var readBuf = new byte[16 * 1024]; int readBufPos = 0; client.BeginRead(readBuf, 0, readBuf.Length, Read, null); // bool found = false; void Read(IAsyncResult ar) { var c = client.EndRead(ar); Profiling.Stamp(TraceCategory.Test, "Test Read Done = " + c); if (c == 0) { Console.WriteLine("Disconnected"); return; } var line = Encoding.UTF8.GetString(readBuf, readBufPos, c); Console.Write(line); // readBufPos += c; // var line = Encoding.UTF8.GetString(readBuf, 0, c); // Console.WriteLine(">>> " + line); // Profiling.Stamp(TraceCategory.Test, "Test Read..."); client.BeginRead(readBuf, readBufPos, readBuf.Length - readBufPos, Read, null); } string q = null; while (q != "q") { var request = Encoding.ASCII.GetBytes($"GET /ncr HTTP/1.1\r\nHost: www.google.com\r\nConnection: keep-alive\r\n\r\n"); client.Write(request, 0, request.Length); q = Console.ReadLine(); } }
public void Check_big_complex_tunel() { // gost_ss -> river_socks -> gost_socks -> river_ss var port = GetFreePort(); var proxy = new AnyProxyServer { Chain = { "ss://*****:*****@rt.xkip.ru:18338", "ss://*****:*****@rt.xkip.ru:18338", "ss://*****:*****@rt.xkip.ru:18338", "ss://*****:*****@rt.xkip.ru:18338", }, }.Track(this); proxy.Run("socks://0.0.0.0:" + port); var connection = new Socks4ClientStream("127.0.0.1", port, Host, 80).Track(this); TestConnction(connection, Host); }
public void Check_20_basic_by_ip() { var cli = new Socks4ClientStream(_proxy, _proxyPort, "127.127.127.127", 80, false).Track(this); TestConnction(cli, _host); }
public void Check_10_basic() { var cli = new Socks4ClientStream(_proxy, _proxyPort, _host, 80, true).Track(this); TestConnction(cli, _host); }
public void Check_socks_by_river4_client() { Stream cli; var ip = new IPAddress(new byte[] { 127, 127, 127, 127 }); using (Scope("Socks4ClientStream - default null")) { cli = new Socks4ClientStream(_proxy, _proxyPort, _host, 80).Track(this); TestConnction(cli, _host); } using (Scope("Socks4ClientStream - v4a force dns")) { cli = new Socks4ClientStream(_proxy, _proxyPort, _host, 80, proxyDns: true).Track(this); TestConnction(cli, _host); } using (Scope("Socks4ClientStream - v4 force i")) { cli = new Socks4ClientStream(_proxy, _proxyPort, _host, 80, proxyDns: false).Track(this); TestConnction(cli, _host); } // IPv4 - native support using (Scope("Socks4ClientStream 4")) { cli = new Socks4ClientStream(_proxy, _proxyPort, ip.ToString(), 80).Track(this); TestConnction(cli, _host); } using (Scope("Socks4ClientStream 5")) { cli = new Socks4ClientStream(_proxy, _proxyPort, ip.ToString(), 80, proxyDns: true).Track(this); TestConnction(cli, _host); } using (Scope("Socks4ClientStream 6")) { cli = new Socks4ClientStream(_proxy, _proxyPort, ip.ToString(), 80, proxyDns: false).Track(this); TestConnction(cli, _host); } using (Scope("Socks5ClientStream")) { // default null cli = new Socks5ClientStream(_proxy, _proxyPort, _host, 80).Track(this); TestConnction(cli, _host); } using (Scope("Socks5ClientStream proxyDns: true")) { // v5 force dns cli = new Socks5ClientStream(_proxy, _proxyPort, _host, 80, proxyDns: true).Track(this); TestConnction(cli, _host); } using (Scope("Socks5ClientStream proxyDns: false - v5 force ip")) { cli = new Socks5ClientStream(_proxy, _proxyPort, _host, 80, proxyDns: false).Track(this); TestConnction(cli, _host); } using (Scope("Socks5ClientStream - IPv4 - native support")) { cli = new Socks5ClientStream(_proxy, _proxyPort, ip.ToString(), 80).Track(this); TestConnction(cli, _host); } using (Scope("Socks5ClientStream proxyDns true")) { cli = new Socks5ClientStream(_proxy, _proxyPort, ip.ToString(), 80, proxyDns: true).Track(this); TestConnction(cli, _host); } using (Scope("Socks5ClientStream proxyDns false")) { cli = new Socks5ClientStream(_proxy, _proxyPort, ip.ToString(), 80, proxyDns: false).Track(this); TestConnction(cli, _host); } }
// [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(); }