當前位置: 首頁>>代碼示例>>C#>>正文


C# CaptureFileReaderDevice.Capture方法代碼示例

本文整理匯總了C#中SharpPcap.LibPcap.CaptureFileReaderDevice.Capture方法的典型用法代碼示例。如果您正苦於以下問題:C# CaptureFileReaderDevice.Capture方法的具體用法?C# CaptureFileReaderDevice.Capture怎麽用?C# CaptureFileReaderDevice.Capture使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SharpPcap.LibPcap.CaptureFileReaderDevice的用法示例。


在下文中一共展示了CaptureFileReaderDevice.Capture方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

        public static void Main (string[] args)
        {
            string ver = SharpPcap.Version.VersionString;

            /* Print SharpPcap version */
            Console.WriteLine("SharpPcap {0}, ReadingCaptureFile", ver);
            Console.WriteLine();

            Console.WriteLine();

            // read the file from stdin or from the command line arguments
            string capFile;
            if(args.Length == 0)
            {
                Console.Write("-- Please enter an input capture file name: ");
                capFile = Console.ReadLine();
            } else
            {
                // use the first argument as the filename
                capFile = args[0];
            }

            Console.WriteLine("opening '{0}'", capFile);

            ICaptureDevice device;

            try
            {
                // Get an offline device
                device = new CaptureFileReaderDevice( capFile );

                // Open the device
                device.Open();
            }
            catch(Exception e)
            {
                Console.WriteLine("Caught exception when opening file" + e.ToString());
                return;
            }

            // Register our handler function to the 'packet arrival' event
            device.OnPacketArrival +=
                new PacketArrivalEventHandler( device_OnPacketArrival );

            Console.WriteLine();
            Console.WriteLine
                ("-- Capturing from '{0}', hit 'Ctrl-C' to exit...",
                capFile);

            // Start capture 'INFINTE' number of packets
            // This method will return when EOF reached.
            device.Capture();

            // Close the pcap device
            device.Close();
            Console.WriteLine("-- End of file reached.");
            Console.Write("Hit 'Enter' to exit...");
            Console.ReadLine();
        }
開發者ID:Praymundo,項目名稱:sharppcap,代碼行數:59,代碼來源:Main.cs

示例2: CaptureFinite

        public void CaptureFinite()
        {
            var device = new CaptureFileReaderDevice("../../capture_files/ipv6_http.pcap");
            device.OnPacketArrival += HandleDeviceOnPacketArrival;
            device.Open();

            var expectedPackets = 3;
            capturedPackets = 0;
            device.Capture(expectedPackets);

            Assert.AreEqual(expectedPackets, capturedPackets);
        }
開發者ID:Praymundo,項目名稱:sharppcap,代碼行數:12,代碼來源:CaptureFileReaderTest.cs

示例3: ReconSingleFileSharpPcap

        /// <summary>
        /// Reconstruct a Pcap file using TcpRecon class
        /// </summary>
        public static List<MemoryStream> ReconSingleFileSharpPcap(string capFile)
        {
            var capture = new CaptureFileReaderDevice(capFile);
            var retVal = new List<MemoryStream>();

            //Register our handler function to the 'packet arrival' event
            capture.OnPacketArrival +=
                new SharpPcap.PacketArrivalEventHandler(device_PcapOnPacketArrival);

            //Start capture 'INFINTE' number of packets
            //This method will return when EOF reached.
            capture.Capture();

            //Close the pcap device
            capture.Close();

            // Clean up
            foreach (TcpRecon tr in sharpPcapDict.Values)
            {
                retVal.Add(tr.data_out_file.BaseStream as MemoryStream);
                tr.Close();
            }
            sharpPcapDict.Clear();
            return retVal;
        }
開發者ID:Farmy,項目名稱:GameMessage-Viewer,代碼行數:28,代碼來源:pCapReader.cs

示例4: ProcessPcap

        public void ProcessPcap()
        {
            sharpPcapDict = new Dictionary<Connection, TcpRecon>();
            PcapDevice device;
            totalPackets = 0;
            totalTCPPackets = 0;

            try
            {
                device  = new SharpPcap.LibPcap.CaptureFileReaderDevice(capFile);
                device.Open();
            }
            catch (Exception ex)
            {
                ErrorMessage = "Error Loading pcap with SharpPcap: " + ex.Message;
                owner.Invoke(Complete, ips);
                return;
            }

            device.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_PcapOnPacketArrival);
            device.Capture(); //parse entire pcap until EOF
            device.Close();

            foreach (TcpRecon tr in sharpPcapDict.Values)
            {
                tr.isComplete = true;
                if (tr.LastSavedOffset != tr.CurrentOffset) AddNewNode(tr);
                tr.Close();
            }

            sharpPcapDict.Clear();
            owner.Invoke(Complete, ips);

            return;
        }
開發者ID:benshu,項目名稱:Visual_TCPRecon,代碼行數:35,代碼來源:ReconManager.cs

示例5: ReadCap

        public void ReadCap(string FilePath)
        {
            ICaptureDevice device = null;

            try
            {
                // Get an offline device
                device = new CaptureFileReaderDevice(FilePath);

                // Open the device
                device.Open();
            }
            catch (Exception e)
            {
                return;
            }

            device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
            device.Capture();
            device.Close();

            //CapFileReader reader = new CapFileReader();
            //reader.ReadCapFile(FilePath);
        }
開發者ID:JackWangCUMT,項目名稱:WiFiSpy,代碼行數:24,代碼來源:CapFile.cs


注:本文中的SharpPcap.LibPcap.CaptureFileReaderDevice.Capture方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。