Packet.Net 是一个.NET程序包,提供了剖析和构建网络数据包的功能。可以通过类的属性来调整各种数据包的参数。
示例代码:
using PacketDotNet; // 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, new PosixTimeval(rawPacket.Timeval.Seconds, rawPacket.Timeval.MicroSeconds), rawPacket.Data); // print out the packet contents Console.WriteLine(p);
输出信息:
[EthernetPacket: 00234D5BF88B -> 00183F7775D1 proto=IpV4 (0x800) l=14][IPv4Packet: 192.168.1.76 -> 72.14.204.83 HeaderLength=5 Protocol=TCP TimeToLive=64][TCPPacket: SourcePort: 59038 -> DestinationPort: 443 ack[218134930 (0xd007992)]]