private void LoadFile(string filename) { using (var pCap = new PCapFile(new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { lock (DataPacketsLock) { DataPackets = pCap.Where(p => p.PacketType != PCapPacketType.Other && !(p.IsBaseIpProtocol || (p.PortSource == 0 && p.PortDestination == 0) || p.Data == null || p.Data.Length == 0)).ToList(); //DataPackets = pCap.ToList(); // Clear statistics searchStats.Clear(); DataPackets.ForEach(row => { if (SearchStats.IsSearchPacket(row)) { searchStats.Add(row); } }); } txtFilter.Text = ""; ShowDataPacket(); } }
public PCapFile Parse() { using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BinaryReader binaryReader = new BinaryReader(fileStream)) { uint magicNumber = binaryReader.ReadUInt32(); if (magicNumber == 0xA1B2C3D4 || magicNumber == 0xD4C3B2A1) { var file = new PCapFile(magicNumber); file.PacketRead += File_PacketRead; file.Parse(binaryReader); return(file); } } } return(null); }
static void Main(string[] args) { //using (var pCap = new PCapFile(new FileStream("network.pcap", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) using (var pCap = new PCapFile(new FileStream(@"c:\temp\ip_mix.pcap", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { while (pCap.HasPacket) { var packet = pCap.Next(); if (packet.PacketType == PCapPacketType.Other) { continue; } if (packet.IsBaseIpProtocol || (packet.PortSource == 0 && packet.PortDestination == 0) || packet.Data == null || packet.Data.Length == 0) { continue; } Console.WriteLine($"Packet: {packet.PacketNumber}, Type: {packet.PacketType}, SourcePort: {packet.PortSource}, DestPort: {packet.PortDestination}, Len: {packet.Data.Length}"); } } }