【问题标题】:Extracting packet details in c#在 C# 中提取数据包详细信息
【发布时间】:2015-01-26 08:04:23
【问题描述】:

我想实现以下功能:

从 pcap 文件中一一获取数据包。我需要根据它们的协议类型来分离数据包。所以基本上我应该能够更改数据包对象,如 ip 地址

我使用的语言是 c#

那么这是否可以使用 Pcap.net 来实现?

任何人都可以使用标准代码吗?请提供给我。

非常感谢 英尺

【问题讨论】:

标签: c# pcap pcap.net


【解决方案1】:

是的,有可能。

请参阅Pcap.Net's tutorial 中的“从转储文件中读取数据包”。

【讨论】:

    【解决方案2】:

    首先,下载PcapDotNet.Core.dllPcapDotNet.Packets.dll,然后创建一个类

    public class Session
    {
        private IList<Packet> _PacketsSequence;
    
        public IList<Packet> PacketsSequence
        {
            get
            {
                if (_PacketsSequence == null)
                    _PacketsSequence = new List<Packet>();
                return _PacketsSequence;
            }
    
            set { _PacketsSequence = value; }
        }
    }
    

    然后创建类

    public class PacketParser
    {
    private List<Session> _TermonatedSessions;
    private IList<Session> _Sessions;
    private IDictionary<int, List<Packet>> _Buffer;
    
    public PacketParser()
    {
        _TermonatedSessions = new List<Session>();
        _Sessions = new List<Session>();
        _Buffer = new Dictionary<int, List<Packet>>();
    }
    
    public void ParsePacket(string filePath)
    {
        OfflinePacketDevice selectedDevice = new OfflinePacketDevice(filePath);
        using (PacketCommunicator communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
        {
            try
            {
                communicator.ReceivePackets(0, AnalyzeCurrentPacket);
            }
            catch { }
        }
    
        var AnalyzedSession = CombineOpenCloseSessions();
    }
    
    private IList<Session> CombineOpenCloseSessions()
    {
        _TermonatedSessions.AddRange(_Sessions);
        _Sessions.Clear();
        _Buffer.Clear();
    
        return _TermonatedSessions;
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-01-09
      • 2019-05-05
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 1970-01-01
      相关资源
      最近更新 更多