Skip to content

Create a simple VPN Client for Windows

Bob edited this page Nov 12, 2022 · 8 revisions

You can establish a VpnHood client connection with a few lines of code. For more information check samples.

Please note it is the simplest VpnHood client connection. If you build a VPN application, you can use other NuGet packages. For more information, check VpnHood NuGet Packages.

👉 Make sure you run your Visual Studio or Developing Environment as an Administrator Account.

First, install the following NuGet packages.

PM> Install-Package VpnHood.Client
PM> Install-Package VpnHood.Client.Device.WinDivert

Here is all enough to establish a VPN connection.

static void Main()
{
	Console.WriteLine("Hello VpnClient!");

	// clientId should be generated for each client
	var clientId = Guid.Parse("7BD6C156-EEA3-43D5-90AF-B118FE47ED0A");

	// accessKey must obtain from the server
	var accessKey = "Your access code";
	var token = Token.FromAccessKey(accessKey);

	var packetCapture = new WinDivertPacketCapture();
	var vpnHoodClient = new VpnHoodClient(packetCapture, clientId, token, new ClientOptions() {});

	vpnHoodClient.Connect().Wait();

	Console.WriteLine("VpnHood Client Is Running!");
	Console.WriteLine("Open your browser and browse the Internet! Press Ctrl+C to stop.");
	while (vpnHoodClient.State == ClientState.Disposed)
		Thread.Sleep(1000);
}