public void PrintString() { Console.WriteLine("Loading the sample capture file"); var dev = new OfflinePcapDevice("../../CaptureFiles/arp_request_response.pcap"); dev.Open(); Console.WriteLine("Reading packet data"); dev.GetNextRawPacket(); var rawPacket = dev.GetNextRawPacket(); dev.Close(); Console.WriteLine("Printing human readable string"); Console.WriteLine(rawPacket.ToString()); }
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { string filePath = String.Empty; if (ofDlg.ShowDialog() == DialogResult.OK) { filePath = ofDlg.FileName; this.lblStatus.Text = "当前文件:" + filePath; OfflinePcapDevice device = new OfflinePcapDevice(filePath); device.Open(); device.OnPacketArrival += new PacketArrivalEventHandler(readPacketArrival); device.Capture(); //此处数据包开始大量到达,引发 readPacketArrival 方法 //TODO:当打开的数据包文件中的数据包数目在1000以上左右,窗体加载数据包,导致长时间无响应 device.Close(); } }
public void ProcessPCapFile(string capFile) { if (string.IsNullOrEmpty(capFile)) { return; } OfflinePcapDevice device = null; try { device = new OfflinePcapDevice(capFile); device.Open(); } catch (Exception ex) { if (Log != null) { Log("Error: File does not exist, not in .pcap format ro you don't have winpcap installed."); } throw new PCapFormatException("Error: File does not exist, not in .pcap format ro you don't have winpcap installed.", ex); } StreamProcessor = new EQStreamProcessor(); if (!StreamProcessor.Init(Application.StartupPath + "\\Configs", Log)) { if (Log != null) { Log("Fatal error initialising Stream Processor. No decoders could be initialised (mostly likely misplaced patch_XXXX.conf files."); } if (SetStatus != null) { SetStatus("Fatal error initialising Stream Processor. No decoders could be initialised (mostly likely misplaced patch_XXXX.conf files."); } return; } if (Options.EQPacketDebugFilename.Text.Length > 0) { try { if (PacketDebugStream == null) { PacketDebugStream = new StreamWriter(Options.EQPacketDebugFilename.Text); } StreamProcessor.Packets.SetDebugLogHandler(PacketDebugLogger); } catch { if (Log != null) { Log("Failed to open netcode debug file for writing."); } Options.EQPacketDebugFilename.Text = ""; StreamProcessor.Packets.SetDebugLogHandler(null); } } else { StreamProcessor.Packets.SetDebugLogHandler(null); } SetStatus("Reading packets from " + capFile + ". Please wait..."); device.OnPacketArrival += device_OnPacketArrival; BytesRead = 0; PacketsSeen = 0; if (Log != null) { Log("-- Capturing from '" + capFile); } ReportProgress(0); CaptureFileSize = device.FileSize; device.Capture(); device.Close(); if (Log != null) { Log("End of file reached. Processed " + PacketsSeen + " packets and " + BytesRead + " bytes."); } }
public void ProcessPCapFile(string capFile) { if (string.IsNullOrEmpty(capFile)) return; OfflinePcapDevice device=null; try { device = new OfflinePcapDevice(capFile); device.Open(); } catch (Exception ex) { if(Log!=null) Log("Error: File does not exist, not in .pcap format ro you don't have winpcap installed."); throw new PCapFormatException("Error: File does not exist, not in .pcap format ro you don't have winpcap installed.", ex); } StreamProcessor = new EQStreamProcessor(); if (!StreamProcessor.Init(Application.StartupPath + "\\Configs", Log)) { if (Log != null) Log("Fatal error initialising Stream Processor. No decoders could be initialised (mostly likely misplaced patch_XXXX.conf files."); if (SetStatus != null) SetStatus("Fatal error initialising Stream Processor. No decoders could be initialised (mostly likely misplaced patch_XXXX.conf files."); return; } if (Options.EQPacketDebugFilename.Text.Length > 0) { try { if(PacketDebugStream==null) PacketDebugStream = new StreamWriter(Options.EQPacketDebugFilename.Text); StreamProcessor.Packets.SetDebugLogHandler(PacketDebugLogger); } catch { if (Log != null) Log("Failed to open netcode debug file for writing."); Options.EQPacketDebugFilename.Text = ""; StreamProcessor.Packets.SetDebugLogHandler(null); } } else StreamProcessor.Packets.SetDebugLogHandler(null); SetStatus( "Reading packets from " + capFile+ ". Please wait..."); device.OnPacketArrival += device_OnPacketArrival; BytesRead = 0; PacketsSeen = 0; if (Log != null) Log("-- Capturing from '" + capFile); ReportProgress(0); CaptureFileSize = device.FileSize; device.Capture(); device.Close(); if(Log!=null)Log("End of file reached. Processed " + PacketsSeen + " packets and " + BytesRead + " bytes."); }