Skip to content

WireGuard Simple Windows Cli and WireGuard NT Wrapper for C#(Csharp) with P/Invoke

License

Notifications You must be signed in to change notification settings

nrajesh9820/WireGuardNTSharp

 
 

Repository files navigation

WireGuardNT PInvoke with Csharp, sharp, Windows

.NET binding over WireGuardNT

WireGuardNT-PInvoke library written in C# targeting .NET Standard 2.0. Version.

WireGuard-Cli

Save the configuration file to the path of the Example program, and then use the following code to load the configuration file.

Also, I created project with reference to the following link.

WireGuardNT/Example.C WireGuardNT/embeddable-dll-service

client.conf

[Interface]
Address = 10.0.0.2/24
ListenPort = 51820
PrivateKey = ==SOME===PRIVATE===key==

[Peer]
PublicKey = ==SOME===PUBLIC===KEY==
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = myserver.dyndns.org:51820

Example->Program.cs

...
NET_LUID adapterLuid;
WgConfig WgConfig = new WgConfig();

var baseName = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); 
var configFile = System.IO.Path.Combine(baseName, "client.conf");
//Read all line from config file
var configAllLinesLine = File.ReadAllLines(configFile);
            
var adapterName = "wgtest";
var tunnelType = "wgtest";

//Create Some GUID
var adapterGuid = Guid.Parse("{0xdeadc001,0xbeef,0xbabe,{0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}}");
//Get Adapter
var adapter = new Adapter(adapterName, tunnelType);
adapter.ParseConfFile(configAllLinesLine, out WgConfig);
...
adapter.SetConfiguration(WgConfig);
adapter.SetStateUp();

And Run the program.

Visual Studio -> Choose WireGuard-Cli -> Run
Run Cmd -> netsh interface show interface or ipconfig

GIF

Using Cli

Release

Usage: WireGuard-Cli.exe [OPTION...]
 -v          version
 -c          config "config file path" default path is "client.conf"
 -n          name "adapter name" default name is "client"
 -t          type "tunnel type" default type is "client"

Nuget Package

WireGuardNT-PInvoke

Install-Package WireGuardNT-PInvoke 

TODO

[ ] IPv6 Support
[ ] Code Refactor
[ ] Nuget Package
[ ] Add more example
[ ] TestCode

About

WireGuard Simple Windows Cli and WireGuard NT Wrapper for C#(Csharp) with P/Invoke

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%