NetWintun is an unofficial C# wrapper around the Wintun library.
Wintun is a minimal, high-performance TUN driver for Windows, providing userspace programs with a simple virtual network adapter for sending and receiving packets.
- 🌀
async/await
support for receiving packets - 📋 Integration with Microsoft.Extensions.Logging
- 🛡️ Robust error handling and resource management
- 🔌 Ships with the prebuilt, signed Wintun binaries.
using var adapter = Adapter.Create("OfficeNet", "Wintun");
using var session = adapter.StartSession(Wintun.Constants.MaxRingCapacity);
session.SendPacket("Hello World"u8);
using var adapter = Adapter.Create("OfficeNet", "Wintun");
using var session = adapter.StartSession(Wintun.Constants.MinRingCapacity);
// Asynchronously wait for a packet
var packet = await session.ReceivePacketAsync();
// Or try to grab one immediately
if (session.TryReceivePacket(out var packet)) {
Console.WriteLine($"Received {packet.Length} bytes");
}
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
Wintun.SetLogger(loggerFactory.CreateLogger<Program>());
👉 Check out the full example program for a working demo.
Before building, unzip the prebuilt Wintun binaries into the /wintun
directory:
/netwintun
├─ src/
├─ examples/
└─ wintun/ <-- unzip here
The contents of the repository are "Copyright (c) 2025 aneilmac".
Source code: Licensed under the MIT License
The library requires usage of wintun.dll. The NetWintun nuget package includes prebuilt and signed Wintun binaries, which are distributed under the terms of the Prebuilt Binaries License. By using NetWintun via NuGet, you agree to the terms of the Wintun Prebuilt Binaries License.