本文整理匯總了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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}