Skip to content

Easy way to create and remove loopback network interfaces on Windows (.NET Framework)

Notifications You must be signed in to change notification settings

theXappy/LoopbackNET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LoopbackNET

Easy way to create and remove loopback network interfaces on Windows (.NET Framework)

Utilizes devcon and netsh.

Privileges

An important note about this library - To use devcon.exe it must be run as an elevated process. This is currently enforced by making a check in LoopbackNET that the current process is elevated when trying to create new loopbacks.

Usage

Create new unnamed/name interface:

LoopbackNET.Loopback.Create();
LoopbackNET.Loopback.Create("myLoopback");

If you want to remove the interface when you are done, keep the result:

LoopbackInterface iface = LoopbackNET.Loopback.Create();
... more code ...
iface.Remove();

Another option is to use the 'using' keyword since LoopbackInterface implements IDisposable:

using(LoopbackInterface iface = LoopbackNET.Loopback.Create())
{
  ... more code ...
}

Working with SharpPcap ( + Npcap )

While SharpPcap is not a requirement for this library, you might want to use your newly created loopback interface with a SharpPcap device object.

You can use the NetworkInterface ID of the created loopback to find the right device like so:

LoopbackInterface iface = LoopbackNET.Loopback.Create();
string interfaceId = iface.NetworkInterface.Id;
ICaptureDevice dev = SharpPcap.CaptureDeviceList.Instance.Single(device => device.Name.Contains(interfaceId));

About

Easy way to create and remove loopback network interfaces on Windows (.NET Framework)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages