Packet.Net is a high performance .NET assembly for constructing and dissecting network packets such as Ethernet, IP, UDP, TCP, etc.
Packet.Net started as a rewrite of the packet parser in SharpPcap with the goal of making a more consistent and better documented API.
The source code package, available via the Downloads link on the project page, contains an Examples/ directory. Below are some snippets that illustrate usage but are not intended to be complete.
Packet.Net can be used to create packets from scratch:
int sourcePort = 10;
int destinationPort = 20;
TcpPacket tcpPacket = new TcpPacket(sourcePort, destinationPort);
Many people will use Packet.Net in conjunction with existing data, either captured from the network via SharpPcap or Pcap.Net to decode packets:
// open the capture file
SharpPcap.LivePcapDevice dev = new SharpPcap.LivePcapDevice("SomeCapturedPackets.pcap");
// read a raw packet
rawPacket = dev.GetNextRawPacket();
// parse the packet
Packet p = Packet.ParsePacket((LinkLayers)rawPacket.LinkLayerType,
// print out the packet contents
This program would produce output like:
[EthernetPacket: 00234D5BF88B -> 00183F7775D1 proto=IpV4 (0x800) l=14][IPv4Packet: 192.168.1.76 -> 220.127.116.11 HeaderLength=5 Protocol=TCP TimeToLive=64][TCPPacket: SourcePort: 59038 -> DestinationPort: 443 ack[218134930 (0xd007992)]]
· Mono Project