Easy way to create and remove loopback network interfaces on Windows (.NET Framework)
Utilizes devcon and netsh.
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.
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:
LoopbackInterfaceiface=LoopbackNET.Loopback.Create();
...more code ...iface.Remove();Another option is to use the 'using' keyword since LoopbackInterface implements IDisposable:
using(LoopbackInterfaceiface=LoopbackNET.Loopback.Create()){
...more code ...}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:
LoopbackInterfaceiface=LoopbackNET.Loopback.Create();stringinterfaceId=iface.NetworkInterface.Id;ICaptureDevicedev=SharpPcap.CaptureDeviceList.Instance.Single(device =>device.Name.Contains(interfaceId));