RuriLib.Proxies 2.0.1

dotnet add package RuriLib.Proxies --version 2.0.1
                    
NuGet\Install-Package RuriLib.Proxies -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RuriLib.Proxies" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RuriLib.Proxies" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="RuriLib.Proxies" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RuriLib.Proxies --version 2.0.1
                    
#r "nuget: RuriLib.Proxies, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RuriLib.Proxies@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RuriLib.Proxies&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=RuriLib.Proxies&version=2.0.1
                    
Install as a Cake Tool

RuriLib.Proxies

This is a library that can proxy a TcpClient via a proxy server. Supported protocols:

  • HTTP
  • SOCKS4
  • SOCKS4a
  • SOCKS5
  • No proxy

All proxy clients derive from the same ProxyClient class, so it's really easy to implement different kinds of proxies (and even proxiless connections) with a simple switch statement in your application.

If you are planning to use this library to send HTTP requests via proxy servers, you should look into the RuriLib.Http library, which depends on this. Only use this library if you are okay with working with raw TCP connections or if you are able to feed the TcpClient into another library that provides support for higher layer protocols.

Requirements

Version 2.x targets .NET 10.

Installation

NuGet: dotnet add package RuriLib.Proxies

Example

using RuriLib.Proxies;
using RuriLib.Proxies.Clients;
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ProxiesDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            _ = MainAsync(args);
            Console.ReadLine();
        }

        static async Task MainAsync(string[] args)
        {
            // Initialize the proxy settings
            var settings = new ProxySettings
            {
                ConnectTimeout = TimeSpan.FromSeconds(10),
                ReadWriteTimeOut = TimeSpan.FromSeconds(30),
                Host = "127.0.0.1",
                Port = 8888,

                // Remove the following line if the proxy does not require authentication
                Credentials = new NetworkCredential("username", "password")
            };

            // Choose one of the following
            var httpProxyClient = new HttpProxyClient(settings); // HTTP proxies
            var socks4ProxyClient = new Socks4ProxyClient(settings); // Socks4 proxies
            var socks4aProxyClient = new Socks4aProxyClient(settings); // Socks4a proxies
            var socks5ProxyClient = new Socks5ProxyClient(settings); // SOCKS5 proxies
            var noProxyClient = new NoProxyClient(settings); // No proxy

            using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(15));

            // Connect to the website via the proxy, we will get a TCP client that we can use
            using var tcpClient = await httpProxyClient.ConnectAsync("example.com", 80,
                cancellationToken: cts.Token);

            // Now you can send messages on the raw TCP socket
            using var netStream = tcpClient.GetStream();
            using var memory = new MemoryStream();

            // Send HELLO
            var requestBytes = Encoding.ASCII.GetBytes("HELLO");
            await netStream.WriteAsync(requestBytes.AsMemory(0, requestBytes.Length));

            // Read the response
            await netStream.CopyToAsync(memory);
            memory.Position = 0;
            var data = memory.ToArray();
            Console.WriteLine(Encoding.UTF8.GetString(data));
        }
    }
}

Changelog

See CHANGELOG.md for release notes.

Credits

Some portions of the code were the work of Ruslan Khuduev and Artem Dontsov, to which I am grateful, all rights are reserved to them. Their work is under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on RuriLib.Proxies:

Package Downloads
RuriLib.Http

This is a library that provides a custom HTTP client, in addition to an HttpMessageHandler to be used with the default HttpClient of System.Net

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 113 6/27/2026
2.0.0 132 6/6/2026
1.0.2 1,752 3/9/2022
1.0.1 2,182 1/9/2022
1.0.0 552 1/7/2022