Pouyan.SingBox 1.0.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pouyan.SingBox --version 1.0.0.8                
NuGet\Install-Package Pouyan.SingBox -Version 1.0.0.8                
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="Pouyan.SingBox" Version="1.0.0.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pouyan.SingBox --version 1.0.0.8                
#r "nuget: Pouyan.SingBox, 1.0.0.8"                
#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.
// Install Pouyan.SingBox as a Cake Addin
#addin nuget:?package=Pouyan.SingBox&version=1.0.0.8

// Install Pouyan.SingBox as a Cake Tool
#tool nuget:?package=Pouyan.SingBox&version=1.0.0.8                

<div align="center">

Pouyan.SingBox

Template project: GitHub

Configure and run sing-box with ease.
Based on sing-box's official documentation.

Nuget Nuget

</div>

Configuration examples

for more configuration examples, including Route Rules or Dns configuration, please refer to sing-box's official documentation.

Mixed inbound:

var mixedInbound = Pouyan.SingBox.Inbound.CreateMixedInbound(
    listen:"127.0.0.1",
    listenPort: 3080
    );

Tun inbound:

  • Please note that tun inbound requires your app to have administrator privileges.
var tunInbound = Pouyan.SingBox.Inbound.CreateTunInbound();

Parse outbound profiles:

var myProfileUrl = "trojan://myLovelyPassword@myserver.server:443?security=tls&sni=mySni&type=grpc&serviceName=myGrpcPath#MyTrojanServer";
var myProfile = ProfileParser.ParseProfileUrl(myProfileUrl);

Additionally you can convert parsed profiles back to string url:

var myProfileUrl = myProfile.ToProfileUrl();

Running

  • In order to use this library for running sing-box you first need to obtain it's executable from its original repository.
  • You need to have the path to this executable and pass it to Tunnel's constructor.
var singbox = new Pouyan.SingBox.Tunnel("sing-box.exe", [mixedInbound]);
  • you can pass a CancellationToken to the SingBoxWrapper.StartAsync method, if you cancel it, the sing-box proccess will end. this parameter is optional.
  • if you need sing-box's logs, you need to subscribe to the Onlog event (optional).
var cts = new CancellationTokenSource();
singbox.StartAsync(myProfile, cts, (sender , log) =>
{
    Console.WriteLine(log);
});

Take outbounds from subscribe:

var profiles = SingBox.GetProfile.GetProfilesFromSubscribe(url);

Url testing

You can use UrlTestAsync classes to easily test if the proxies are healthy and valid

var myProfileUrl = "trojan://myLovelyPassword@myserver.server:443?security=tls&sni=mySni&type=grpc&serviceName=myGrpcPath#MyTrojanServer";
var myProfile = ProfileParser.ParseProfileUrl(myProfileUrl);

var profileTester = new ProfileTester("sing-box.exe");

var test = await profileTester.UrlTestAsync(myProfile, 7087);

Console.WriteLine($"Success: {test.Result.Success}, Delay: {test.Result.Delay}");

List<ProfileItem>:

var test = await profileTester.UrlTestAsync(profiles);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0.10 91 9/21/2024
1.0.0.9 98 8/29/2024
1.0.0.8 110 8/23/2024
1.0.0.7 115 8/12/2024
1.0.0.6 100 7/20/2024
1.0.0.5 89 7/17/2024
1.0.0.4 102 7/17/2024
1.0.0.3 99 6/19/2024
1.0.0.2 98 6/19/2024
1.0.0.1 96 6/17/2024
1.0.0 102 6/1/2024