From 40cf4c7170d69c300c0cfb0900a3d97732c6e3dd Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Aug 2021 00:18:32 +0300 Subject: [PATCH] Fix a bug - selecting wrong interface for live capture --- BruteShark/PcapProcessor/Sniffer.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/BruteShark/PcapProcessor/Sniffer.cs b/BruteShark/PcapProcessor/Sniffer.cs index c545590..e1786e9 100644 --- a/BruteShark/PcapProcessor/Sniffer.cs +++ b/BruteShark/PcapProcessor/Sniffer.cs @@ -64,7 +64,9 @@ public void StartSniffing(CancellationToken ct) if (selectedDevice is SharpPcap.LibPcap.LibPcapLiveDevice) { var livePcapDevice = selectedDevice as SharpPcap.LibPcap.LibPcapLiveDevice; - livePcapDevice.Open(PromisciousMode ? SharpPcap.DeviceModes.Promiscuous : SharpPcap.DeviceModes.None); + livePcapDevice.Open(mode: PromisciousMode ? SharpPcap.DeviceModes.Promiscuous : SharpPcap.DeviceModes.None + | DeviceModes.DataTransferUdp + | DeviceModes.NoCaptureLocal); } else { @@ -98,7 +100,7 @@ public void StartSniffing(CancellationToken ct) // Raise events for unfinished sessions. HandleUnfinishedSessions(); } - + private void SetupBpfFilter(ICaptureDevice selectedDevice) { if (this.Filter != null && this.Filter != string.Empty) @@ -136,14 +138,10 @@ private void ClearOldSniffingsData() private SharpPcap.ICaptureDevice GetSelectedDevice() { - var availiableDevices = CaptureDeviceList.Instance; - - if (!AvailiableDevicesNames.Contains(this.SelectedDeviceName)) - { - throw new Exception($"No such device {SelectedDeviceName}"); - } - - return availiableDevices[AvailiableDevicesNames.IndexOf(this.SelectedDeviceName)]; + return CaptureDeviceList.Instance + .Select(d => (PcapDevice)d) + .Where(d => d.Interface.FriendlyName == this.SelectedDeviceName) + .FirstOrDefault(); } private void StartPacketProcessingThread()