TapTunHelperCsharp 1.0.7

dotnet add package TapTunHelperCsharp --version 1.0.7
                    
NuGet\Install-Package TapTunHelperCsharp -Version 1.0.7
                    
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="TapTunHelperCsharp" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TapTunHelperCsharp" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="TapTunHelperCsharp" />
                    
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 TapTunHelperCsharp --version 1.0.7
                    
#r "nuget: TapTunHelperCsharp, 1.0.7"
                    
#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 TapTunHelperCsharp@1.0.7
                    
#: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=TapTunHelperCsharp&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=TapTunHelperCsharp&version=1.0.7
                    
Install as a Cake Tool

English

TapTunHelperCsharp

NuGet Version NuGet Downloads License

介绍

本项目为 taptun-helper C 库提供了跨平台的 .NET 封装,允许你在 C# 中轻松地创建和管理 TUN/TAP 虚拟网络设备。

它将底层的 C 函数调用抽象为简单易用的 C# 类,并自动处理跨平台(Windows 和 Linux)的动态链接库加载。

特性

  • 跨平台:在 Windows 和 Linux 上提供统一的 API。
  • 简单易用:通过 TapTun 类管理设备的完整生命周期。
  • 面向对象:将设备句柄和状态封装在对象中,通过 IDisposable 模式确保资源被正确释放。
  • 功能完整:支持激活设备、设置 IPv4/IPv6 地址、获取 MAC 地址以及读写网络数据包。

开始使用

安装

你可以通过 NuGet 包管理器来安装 TapTunHelperCsharp

Package Manager (Visual Studio):

NuGet\Install-Package TapTunHelperCsharp

示范

using TapTunHelperCsharp;
using System;
using System.Text;

using var tapTun = new TapTun();

Console.WriteLine($"[INFO] Device opened: {tapTun.DeviceInfo.IfName}");

// 激活设备
if (!tapTun.Activate())
{
    Console.WriteLine("[ERROR] Failed to activate device.");
    return;
}
Console.WriteLine("[INFO] Device activated.");

// 设置 IP 地址
if (!tapTun.SetIPAddress("10.0.8.1", "255.255.255.0"))
{
    Console.WriteLine("[ERROR] Failed to set IP address.");
    return;
}
Console.WriteLine("[INFO] IP address set to 10.0.8.1");

// 获取 MAC 地址
var macAddress = tapTun.GetMacAddress();
if (macAddress != null)
{
    Console.WriteLine($"[INFO] MAC Address: {BitConverter.ToString(macAddress)}");
}

// 循环读取数据包
Console.WriteLine("[INFO] Waiting for incoming packets...");
var buffer = new byte;
while (true)
{
    try
    {
        int bytesRead = tapTun.Read(buffer);
        if (bytesRead > 0)
        {
            Console.WriteLine($"[DATA] Received {bytesRead} bytes.");
            // 在这里处理你的数据包...
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"[ERROR] An error occurred while reading: {ex.Message}");
        break;
    }
}
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net8.0

    • No dependencies.

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.7 248 9/11/2025
1.0.6 220 9/8/2025
1.0.5 219 9/8/2025
1.0.4 214 9/8/2025