示例#1
1
 private void _Receive(int count = 0)
 {
     //using (_communicator = _device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
     //{
     //    _ppacketManager = new PPacketManager();
     //    if (_filter != null)
     //        _communicator.SetFilter(_filter);
     //    _communicator.ReceivePackets(0, ReceivePacketHandle);
     //}
     try
     {
         _communicator = _device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000);
         if (_dumpFile != null)
             _packetDumpFile = _communicator.OpenDump(_dumpFile);
         _ppacketManager = new PPacketManager();
         if (_filter != null)
             _communicator.SetFilter(_filter);
         _communicator.ReceivePackets(count, ReceivePacketHandle);
     }
     finally
     {
         if (_communicator != null)
         {
             _communicator.Dispose();
             _communicator = null;
         }
         if (_packetDumpFile != null)
         {
             _packetDumpFile.Dispose();
             _packetDumpFile = null;
         }
     }
 }
示例#2
0
        public static void Test_PrintPacketsDetail_01(string deviceName = null)
        {
            _tr.WriteLine("Test_PrintPacketsDetail_01");

            PacketDevice device = SelectDevice(deviceName);
            if (device == null)
                return;

            __communicator = null;
            //_rs.OnAbortExecution += new OnAbortEvent(OnAbortExecution);
            _rs.OnAbortExecution = OnAbortExecution;
            try
            {
                using (__communicator = device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
                {
                    _tr.WriteLine("Listening on " + device.Description + "...");

                    PPacketManager ppacketManager = new PPacketManager();
                    //PrintPacketDetail print = new PrintPacketDetail();
                    //__communicator.ReceivePackets(5, packet => PrintPacketDetailHandlerOld(ppacketManager.CreatePPacket(packet)));
                    __communicator.ReceivePackets(5, packet => PrintPacketDetail.PrintPacketDetailHandler(ppacketManager.CreatePPacket(packet)));
                }
            }
            finally
            {
                //_rs.OnAbortExecution -= new OnAbortEvent(OnAbortExecution);
            }
        }
示例#3
0
 private void _Analyze(ReceivePackets receivePackets, string directory)
 {
     _directory = directory;
     _ppacketManager = new PPacketManager();
     try
     {
         receivePackets.Receive(PacketHandle);
     }
     finally
     {
         foreach(TcpStream tcpStream in _tcpStreamList.Values)
             tcpStream.Dispose();
     }
 }
示例#4
0
 private void _Analyze(ReceivePackets receivePackets, string directory)
 {
     _directory      = directory;
     _ppacketManager = new PPacketManager();
     try
     {
         receivePackets.Receive(PacketHandle);
     }
     finally
     {
         foreach (TcpStream tcpStream in _tcpStreamList.Values)
         {
             tcpStream.Dispose();
         }
     }
 }
示例#5
0
        public static void Test_PrintPackets_01(string deviceName = null, bool detail = false)
        {
            _tr.WriteLine("Test_PrintPackets_01");

            //string dumpFile = @"dump\dump.pcap";
            //string dumpFile = @"dump\dump.pcapng";
            //dumpFile = GetPath(dumpFile);
            PacketDevice device = SelectDevice(deviceName);
            if (device == null)
                return;

            __communicator = null;
            //_rs.OnAbortExecution += new OnAbortEvent(OnAbortExecution);
            _rs.OnAbortExecution = OnAbortExecution;
            try
            {
                using (__communicator = device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
                {
                    //using (BerkeleyPacketFilter filter = __communicator.CreateFilter("ip and udp"))
                    //{
                    //    __communicator.SetFilter(filter);
                    //}

                    _tr.WriteLine("Listening on " + device.Description + "...");

                    //__communicator.ReceivePackets(0, PrintPacketHandler1);
                    //__communicator.zReceivePackets(0, PrintPacketHandler2);

                    PPacketManager ppacketManager = new PPacketManager();
                    PrintPacketHandler2Header();
                    //__communicator.ReceivePackets(0, packet => PrintPacketHandler2(ppacketManager.CreatePPacket(packet), detail));
                    __communicator.ReceivePackets(0, packet => PrintPacket.PrintPacket1(ppacketManager.CreatePPacket(packet), detail));
                }
            }
            //catch (Exception ex)
            //{
            //    _tr.WriteLine(ex.Message);
            //}
            finally
            {
                //_rs.OnAbortExecution -= new OnAbortEvent(OnAbortExecution);
            }
        }
示例#6
0
 private void _Receive(int count = 0)
 {
     //using (_communicator = _device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
     //{
     //    _ppacketManager = new PPacketManager();
     //    if (_filter != null)
     //        _communicator.SetFilter(_filter);
     //    _communicator.ReceivePackets(0, ReceivePacketHandle);
     //}
     try
     {
         _communicator = _device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000);
         if (_dumpFile != null)
         {
             _packetDumpFile = _communicator.OpenDump(_dumpFile);
         }
         _ppacketManager = new PPacketManager();
         if (_filter != null)
         {
             _communicator.SetFilter(_filter);
         }
         _communicator.ReceivePackets(count, ReceivePacketHandle);
     }
     finally
     {
         if (_communicator != null)
         {
             _communicator.Dispose();
             _communicator = null;
         }
         if (_packetDumpFile != null)
         {
             _packetDumpFile.Dispose();
             _packetDumpFile = null;
         }
     }
 }
示例#7
0
        public static void Test_AnalyzeTcpStreamTest_ReadPcap_01(string file)
        {
            Trace.WriteLine("Test_AnalyzeTcpStreamTest_ReadPcap_01");
            Trace.WriteLine("pcap file \"{0}\"", file);
            Pib.Pcap.Test.AnalyzeTcpStreamTest tcpAnalyze = new Pib.Pcap.Test.AnalyzeTcpStreamTest();
            using (PcapFileReader pcapFileReader = new PcapFileReader(GetPath(file)))
            {
                PPacketManager ppacketManager = new PPacketManager();
                foreach (PcapPacket packet in pcapFileReader)
                {
                    Packet packet2 = new Packet(packet.Data, packet.Timestamp, DataLinkKind.Ethernet);
                    tcpAnalyze.Add(ppacketManager.CreatePPacket(packet2));
                }
            }

            Trace.WriteLine("{0} packet captured", tcpAnalyze.Packets.Count);
            //var q = from p in gPacketList where p.TCPHeader != null orderby p.gGroupNumber, p.PacketNumber select p;
            var q = from p in tcpAnalyze.Packets where p.PPacket.Tcp != null orderby p.StreamNumber, p.PPacket.PacketNumber select p;
            Trace.WriteLine("{0} packet selectionned", q.Count());
            foreach (Pib.Pcap.Test.TcpStreamPacket p in q)
                PrintStreamPacket(p);
        }