コード例 #1
0
        public void Process_PacketBatch_TwoPacket()
        {
            var randomIPNonTcpPacket = IPPacket.RandomPacket(IPVersion.IPv4);

            var randomIPPacket  = IPPacket.RandomPacket(IPVersion.IPv4);
            var randomTCPPacket = TcpPacket.RandomPacket();

            randomIPPacket.PayloadPacket = randomTCPPacket;
            //Arrange
            var posixTimeval  = new PosixTimeval();
            var rawTCPCapture = new RawCapture(LinkLayers.Raw, posixTimeval, randomIPPacket.Bytes);

            var rawNonTCPCapture = new RawCapture(LinkLayers.Raw, posixTimeval, randomIPNonTcpPacket.Bytes);

            var rawPacketBatchRequest =
                new RawPacketBatchRequest(
                    new[] { new RawPacket(rawTCPCapture), new RawPacket(rawNonTCPCapture), new RawPacket(rawTCPCapture) }, 1);

            //Act
            this._rawPacketBatchParserActorRefSUT.Tell(rawPacketBatchRequest);

            //Assert
            this._captureActorTestProbe.ExpectMsg <Frame>(frame => frame.TimestampTicks == posixTimeval.Date.Ticks);
            this._captureActorTestProbe.ExpectMsg <Frame>(frame => frame.TimestampTicks == posixTimeval.Date.Ticks);
            this._captureActorTestProbe.ExpectNoMsg();
        }
コード例 #2
0
        private EthernetPacket BuildNonContiguousEthernetPacket()
        {
            // build an ethernet packet
            var ethernetPacket = EthernetPacket.RandomPacket();

            // build an ip packet
            var ipPacket = IPPacket.RandomPacket(IPVersion.IPv6);

            ethernetPacket.PayloadPacket = ipPacket;

            return(ethernetPacket);
        }
コード例 #3
0
        public void Process_PacketBatch_NonTransportPacket()
        {
            var randomIPPacket = IPPacket.RandomPacket(IPVersion.IPv4);
            //Arrange
            var posixTimeval = new PosixTimeval();
            var rawCapture   = new RawCapture(LinkLayers.Raw, posixTimeval, randomIPPacket.Bytes);

            var rawPacketBatchRequest = new RawPacketBatchRequest(new[] { new RawPacket(rawCapture) }, 1);

            //Act
            this._rawPacketBatchParserActorRefSUT.Tell(rawPacketBatchRequest);

            //Assert
            this._captureActorTestProbe.ExpectNoMsg();
        }
コード例 #4
0
        public void BuildEthernetPacket()
        {
            var tcpPacket      = TcpPacket.RandomPacket();
            var ipPacket       = IPPacket.RandomPacket(IPVersion.IPv4);
            var ethernetPacket = EthernetPacket.RandomPacket();

            // put these all together into a single packet
            ipPacket.PayloadPacket       = tcpPacket;
            ethernetPacket.PayloadPacket = ipPacket;

            Console.WriteLine("random packet: {0}", ethernetPacket);

            // and get a byte array that represents the single packet
            var bytes = ethernetPacket.Bytes;

            // and re-parse that packet
            var newPacket = Packet.ParsePacket(LinkLayers.Ethernet,
                                               bytes);

            Console.WriteLine("re-parsed random packet: {0}", newPacket);
        }
コード例 #5
0
ファイル: CaptureForm.cs プロジェクト: Vex788/TrafficAnalyzer
        void device_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            if (manipulated)
            {
                var packet = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
                try
                {
                    if (packet is PacketDotNet.EthernetPacket)
                    {
                        var eth = EthernetPacket.RandomPacket();
                        logWriting("Random Eth packet: " + eth.ToString());
                        if (eth != null)
                        {
                            // manipulate ethernet parameters
                            eth.SourceHwAddress      = manipulationForm.sourcehw;
                            eth.DestinationHwAddress = manipulationForm.destinationhw;

                            packet = eth;

                            var ip = IPPacket.RandomPacket(IPVersion.IPv4);
                            if (manipulationForm.sourceip != null && manipulationForm.destinationip != null)
                            {
                                logWriting("Random IP packet: " + ip.ToString());

                                // manipulate IP parameters
                                ip.SourceAddress      = manipulationForm.sourceip;
                                ip.DestinationAddress = manipulationForm.destinationip;
                                ip.TimeToLive         = manipulationForm.timeToLive;

                                packet = ip;

                                var tcp = TcpPacket.RandomPacket();
                                if (manipulationForm.sourceTcpPort != 0 && manipulationForm.destinationTcpPort != 0)
                                {
                                    logWriting("Random TCP packet: " + tcp.ToString());

                                    // manipulate TCP parameters
                                    tcp.SourcePort           = manipulationForm.sourceTcpPort;
                                    tcp.DestinationPort      = manipulationForm.destinationTcpPort;
                                    tcp.Syn                  = !tcp.Syn;
                                    tcp.Fin                  = !tcp.Fin;
                                    tcp.Ack                  = !tcp.Ack;
                                    tcp.WindowSize           = manipulationForm.windowSize;
                                    tcp.AcknowledgmentNumber = manipulationForm.acknowledgmentNumber;
                                    tcp.SequenceNumber       = manipulationForm.sequence_number;

                                    packet = tcp;
                                }

                                var udp = UdpPacket.RandomPacket();
                                if (manipulationForm.sourcePort != 0 && manipulationForm.destinationPort != 0)
                                {
                                    logWriting("Random UDP packet: " + udp.ToString());

                                    // manipulate UDP parameters
                                    udp.SourcePort      = manipulationForm.sourcePort;      // 9999
                                    udp.DestinationPort = manipulationForm.destinationPort; // 8888

                                    packet = udp;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    logWriting("Error packet send: " + ex.ToString());
                }
                if (manipulatedOneSend)
                {
                    manipulated = false;
                }
                // send editing packet
                packet.UpdateCalculatedValues();
                for (int i = 0; i < 1000; i++)
                {
                    device.SendPacket(packet);
                }
            }

            // print out periodic statistics about this device
            var Now      = DateTime.Now; // cache 'DateTime.Now' for minor reduction in cpu overhead
            var interval = Now - LastStatisticsOutput;

            if (interval > LastStatisticsInterval)
            {
                logWriting("device_OnPacketArrival: " + e.Device.Statistics);
                captureStatistics       = e.Device.Statistics;
                statisticsUiNeedsUpdate = true;
                LastStatisticsOutput    = Now;
            }

            // lock QueueLock to prevent multiple threads accessing PacketQueue at
            // the same time
            lock (QueueLock)
            {
                PacketQueue.Add(e.Packet);
            }
        }