Esempio n. 1
0
        private void SaveCapturedPacketsToFile()
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                device.Open();

                // Open or create a capture output file
                device.DumpOpen(saveFileDialog.FileName);

                foreach (Packet packet in packetsDictionary.Values)
                {
                    device.Dump(packet);
                }

                device.DumpFlush();

                // Set the flag packetsHaveBeenSaved to true - the displayed packets
                // have just been saved.
                capturedPacketsHaveBeenSaved = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                device.DumpClose();
                device.Close();

                Cursor = Cursors.Default;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Dumps each received packet to a pcap file
        /// </summary>
        private static void device_PcapOnPacketArrival(object sender, PcapCaptureEventArgs e)
        {
            PcapDevice device = (PcapDevice)sender;

            //if device has a dump file opened
            if (device.DumpOpened)
            {
                //dump the packet to the file
                device.Dump(e.Packet);
                Console.WriteLine("Packet dumped to file.");
            }
        }