如何将 Pcap.Net 数据包类对象导出到 .pcap 文件 [英] How do I export Pcap.Net Packet Class Object To .pcap File
问题描述
我正在开发一个应用程序,用户将在其中使用我的工具,但是每次该工具遇到一些数据包时,它都会将 c# 中的数据包类作为 .pcap 文件上传到我的站点,以便我可以亲自检查并制作必要的改变.我想知道是否有人知道我可以实现这个目标的方法.
I am developing an application in which users will use my tool, but every time the tool encounters some packets it will upload the packet class in c# as a .pcap file up to my site so that I can personally inspect it and make the necessary changes. I was wondering if anyone knew of a way for me to accomplish this goal of mine.
public XXXXXCapturer(LivePacketDevice globalDevice) {
PacketCommunicator globalCommunicator = globalDevice.Open(512, PacketDeviceOpenAttributes.Promiscuous, 1000);
using (BerkeleyPacketFilter filter = globalCommunicator.CreateFilter("ether host XX:XX:XX:XX:XX:XX"))
{
globalCommunicator.SetFilter(filter);
}
globalCommunicator.NonBlocking = false;
globalCommunicator.ReceivePackets(1, HandlePackets);
}
private void HandlePackets(Packet packet)
{
XXXXXDecoder Decoder = new XXXXXDecoder(packet);
// Get Packet & Upload
Info = new XXXXXInfo(Decoder.Data);
}
推荐答案
在发布这个问题之前我已经找了几个小时,但没有找到任何结果,所以当我等待有人希望回答这个问题时,我决定我会深入研究并开始查看Pcap.Net
的一些代码.那时我发现了名为 PcapDumpFile
的静态类和一个名为 Dump()
的方法.那个带有一些参数的方法完成了我在这个问题中的要求.我会留下这个问题,因为我希望有类似问题的其他人可能会因此得到帮助.
I have looked for hours prior to posting this question and found no results, so while I waited for someone to hopefully reply to this question I decided I would dive in and start viewing some of the code of Pcap.Net
. That is when I found the static class called PcapDumpFile
with a method called Dump()
. That method with a few arguments accomplished what I asked of in this question. I will leave this question up because I am hoping someone else with a similar question may be helped by this.
我的Dump()
方法用法:
My Dump()
method usage:
PacketDumpFile.Dump(System.IO.Directory.GetLogicalDrives()[0] + @"Program Files (x86)\XXXXX\" + "temp.pcap", packet.DataLink.Kind, packet.Length, new List<Packet> { packet });
这篇关于如何将 Pcap.Net 数据包类对象导出到 .pcap 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!