SharpPcap/C# Problem opening the enp3s0 interface

56 views Asked by At

there is the following code:

using SharpPcap;

CaptureDeviceList devicesList = CaptureDeviceList.Instance;

ICaptureDevice captureDevice = devicesList[0];

captureDevice.OnPacketArrival += new

PacketArrivalEventHandler(Program_onPacketArrival);

captureDevice.Open();

captureDevice.Filter = "(tcp src port 15203) and (greater 360 and less 420)";

captureDevice.Capture();

static void Program_onPacketArrival(object sender, SharpPcap.PacketCapture e)
{
   var packet = e.GetPacket();

   System.Console.WriteLine(packet);
}

I'm trying to sniff tcp packets on the enp3s0 interface, but when opening this interface, an exception occurs:

"Unhandled exception. SharpPcap.PcapException: Unable to activate the adapter (enp3s0). (Error Code: PermissionDenied) at SharpPcap.LibPcap.LibPcapLiveDevice.Open(DeviceConfiguration configuration) at SharpPcap.CaptureDeviceExtensions.Open(IPcapDevice device, DeviceModes mode, Int32 read_timeout) at Program.$(String[] args) in /home/.../VSCodeProjects/stud/Program.cs:line 15".

Code execution environment: vs code
kernel os: Linux 5.15.0-87-generic
package version SharpPcap: 6.2.5
.NET platform version: 6.0

What are the options for solving this problem?


Installed different versions of the SharpPcap package, opened the project with root/sudo, to no avail

0

There are 0 answers