Home

Awesome

.NET Core

sharppcap

Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets from live and file based devices

The official SharpPcap repository.

Table of Contents

  1. Features
  2. Examples
  3. CI Support
  4. Releases
  5. Platform Specific Notes
  6. Migration from 5.x to 6.0

<a name="features"></a>

Features

For packet dissection and creation, see Packet.Net.

<a name="examples"></a>

Examples

See the Examples folder for a range of full example projects using SharpPcap

<a name="listing-devices"></a>

Listing devices

var devices = CaptureDeviceList.Instance;
foreach (var dev in devices)
    Console.WriteLine("{0}\n", dev.ToString());

<a name="capturing-packets"></a>

Capturing packets

void Device_OnPacketArrival(object s, PacketCapture e)
{
    Console.WriteLine(e.GetPacket());
}

using var device = LibPcapLiveDeviceList.Instance[0];
device.Open();
device.OnPacketArrival += Device_OnPacketArrival;
device.StartCapture();

<a name="reading-from-a-capture-file"></a>

Reading from a capture file

void Device_OnPacketArrival(object s, PacketCapture e)
{
    Console.WriteLine(e.GetPacket());
}

using var device = new CaptureFileReaderDevice("filename.pcap");
device.Open();
device.OnPacketArrival += Device_OnPacketArrival;
device.Capture();

<a name="writing-to-a-capture-file"></a>

Writing to a capture file

using var device = new CaptureFileWriterDevice("somefilename.pcap", System.IO.FileMode.Open);
var bytes = new byte[] { 1, 2, 3, 4 };
device.Write(bytes);

<a name="ci-support"></a>

CI support

We have support for a number of CI systems for a few reasons:

<a name="releases"></a>

Releases

SharpPcap is released via nuget

<a name="platform-specific-notes"></a>

Platform specific notes

Thanks

SharpPcap is where it is today because of a number of developers who have provided improvements and fixes and users that have provided helpful feedback through issues and feature requests.

We are especially appreciative of a number of projects we build upon (as SharpPcap is a C# wrapper):

<a name="migration-from-5x-to-60"></a>

Migration from 5.x to 6.0

We hope that you'll find the 6.x api to be cleaner and easier to use.

6.0 brings a number of cleanups that have resulted in API breakage for 5.x users.

To aid with the migration from 5.x to 6.0 here is a list of some of the changes you'll have to make to your SharpPcap usage.

The examples are also a great resource as they show working examples using the latest API.