Created
October 3, 2018 15:08
-
-
Save m1k1o/c492d83ff09a62413541b18600162310 to your computer and use it in GitHub Desktop.
SharpPcap NoCaptureLocal Workaround using Cluster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using SharpPcap; | |
namespace Workaround | |
{ | |
class Cluster | |
{ | |
private static List<CaptureEventArgs> SentPackets = new List<CaptureEventArgs>(); | |
private static object Lock = new object(); | |
public static void Set(CaptureEventArgs e) | |
{ | |
lock (Lock) | |
{ | |
SentPackets.Add(e); | |
} | |
} | |
public static bool Check(CaptureEventArgs e) | |
{ | |
lock (Lock) | |
{ | |
foreach (var Pk in SentPackets) | |
{ | |
if (Pk.Packet.Data.SequenceEqual(e.Packet.Data) && Pk.Device == e.Device) | |
{ | |
SentPackets.Remove(Pk); | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
} | |
class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
foreach (var dev in CaptureDeviceList.Instance) | |
{ | |
dev.Open(); | |
dev.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival); | |
dev.StartCapture(); | |
} | |
} | |
private static void device_OnPacketArrival(object sender, CaptureEventArgs e) | |
{ | |
if (Cluster.Check(e)) | |
{ | |
return; | |
} | |
foreach (var dev in CaptureDeviceList.Instance) | |
{ | |
if (dev.Name.ToString() == e.Device.Name.ToString()) | |
{ | |
continue; | |
} | |
dev.SendPacket(e.Packet.Data); | |
Cluster.Set(new CaptureEventArgs(e.Packet, dev)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment