2
votes

I want to implement following functionality :

fetching one by one packets from pcap file. I need to separate packets depending on their protocol type. so basically i should be able to change packet objects like ip address

language i am using is c#

So is this possible to implement using Pcap.net ?

Is there standard code available with anybody ? please provide me that.

Thanks a lot ftm

2
What have you tried? Have you taken a look at the Pcap.net tutorial (pcapdotnet.codeplex.com/wikipage?title=Pcap.Net%20Tutorial)?Jonny

2 Answers

1
votes

Yes, it is possible.

See "Reading packets from a dump file" in Pcap.Net's tutorial.

-1
votes

first, download PcapDotNet.Core.dll and PcapDotNet.Packets.dll and after create a class

public class Session
{
    private IList<Packet> _PacketsSequence;

    public IList<Packet> PacketsSequence
    {
        get
        {
            if (_PacketsSequence == null)
                _PacketsSequence = new List<Packet>();
            return _PacketsSequence;
        }

        set { _PacketsSequence = value; }
    }
}

then create the class

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;
}
}