private void Device_OnPacketArrival(object sender, PacketCapture e) { if (e.GetPacket().LinkLayerType != PacketDotNet.LinkLayers.Ethernet) { return; } var packet = Packet.ParsePacket(e.GetPacket().LinkLayerType, e.GetPacket().Data); var ethernetPacket = (EthernetPacket)packet; var requestItem = new PCAPFeatureExtractionRequestItem(ethernetPacket.PayloadPacket.Bytes); _packetPredictions.Add(_mlEngine.Predict(requestItem)); }
private void InsertPacketToQueue(object sender, PacketCapture e) { var packet = PacketDotNet.Packet.ParsePacket(e.GetPacket().LinkLayerType, e.GetPacket().Data); lock (_packetsQueueLock) { _packets.Enqueue(packet); } }
/// <summary> /// Prints the time and length of each received packet /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { var time = e.Header.Timeval.Date; var len = e.Data.Length; var rawPacket = e.GetPacket(); Console.WriteLine("{0}:{1}:{2},{3} Len={4}", time.Hour, time.Minute, time.Second, time.Millisecond, len); Console.WriteLine(rawPacket.ToString()); }
private static void Device_OnPacketArrival(object sender, PacketCapture e) { var device = (WinpkFilterDevice)sender; var packet = e.GetPacket().GetPacket(); if (packet.PayloadPacket is IPPacket ip) { Console.WriteLine(ip.ToString(StringOutputType.Colored)); } device.SendPacket(e.Data, e.Header); }
private void device_OnPacketArrival(object sender, PacketCapture e) { if (!sniffEnabled) { return; } lock (packetQueue) { packetQueue.Add(e.GetPacket()); } }
private static void device_OnPacketArrival(object sender, PacketCapture e) { var rawPacket = e.GetPacket(); var packet = PacketDotNet.Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data); if (packet is PacketDotNet.EthernetPacket eth) { Console.WriteLine("Original Eth packet: " + eth.ToString()); //Manipulate ethernet parameters eth.SourceHardwareAddress = PhysicalAddress.Parse("00-11-22-33-44-55"); eth.DestinationHardwareAddress = PhysicalAddress.Parse("00-99-88-77-66-55"); var ip = packet.Extract <PacketDotNet.IPPacket>(); if (ip != null) { Console.WriteLine("Original IP packet: " + ip.ToString()); //manipulate IP parameters ip.SourceAddress = System.Net.IPAddress.Parse("1.2.3.4"); ip.DestinationAddress = System.Net.IPAddress.Parse("44.33.22.11"); ip.TimeToLive = 11; var tcp = packet.Extract <PacketDotNet.TcpPacket>(); if (tcp != null) { Console.WriteLine("Original TCP packet: " + tcp.ToString()); //manipulate TCP parameters tcp.SourcePort = 9999; tcp.DestinationPort = 8888; tcp.Synchronize = !tcp.Synchronize; tcp.Finished = !tcp.Finished; tcp.Acknowledgment = !tcp.Acknowledgment; tcp.WindowSize = 500; tcp.AcknowledgmentNumber = 800; tcp.SequenceNumber = 800; } var udp = packet.Extract <PacketDotNet.UdpPacket>(); if (udp != null) { Console.WriteLine("Original UDP packet: " + udp.ToString()); //manipulate UDP parameters udp.SourcePort = 9999; udp.DestinationPort = 8888; } } Console.WriteLine("Manipulated Eth packet: " + eth.ToString()); } }
/// <summary> /// Prints the time and length of each received packet /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { PacketCount++; var rawPacket = e.GetPacket(); var p = PacketDotNet.Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data); var tcpPacket = p.Extract <TcpPacket>(); if (tcpPacket != null) { log.Debug("passing packet to TcpConnectionManager"); tcpConnectionManager.ProcessPacket(rawPacket.Timeval, tcpPacket); } }
/// <summary> /// Prints the time and length of each received packet /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { // 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) { Console.WriteLine("device_OnPacketArrival: " + e.Device.Statistics); LastStatisticsOutput = Now; } // lock QueueLock to prevent multiple threads accessing PacketQueue at // the same time lock (QueueLock) { PacketQueue.Add(e.GetPacket()); } }
/// <summary> /// Prints the source and dest MAC addresses of each received Ethernet frame /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { packetIndex++; var rawPacket = e.GetPacket(); var packet = PacketDotNet.Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data); var ethernetPacket = packet.Extract <EthernetPacket>(); if (ethernetPacket != null) { Console.WriteLine("{0} At: {1}:{2}: MAC:{3} -> MAC:{4}", packetIndex, e.Header.Timeval.Date.ToString(), e.Header.Timeval.Date.Millisecond, ethernetPacket.SourceHardwareAddress, ethernetPacket.DestinationHardwareAddress); } }
/// <summary> /// Prints the time and length of each received packet /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { #if false var time = e.Packet.Timeval.Date; var len = e.Packet.Data.Length; Console.WriteLine("{0}:{1}:{2},{3} Len={4}", time.Hour, time.Minute, time.Second, time.Millisecond, len); Console.WriteLine(e.Packet.ToString()); #endif var rawPacket = e.GetPacket(); var p = PacketDotNet.Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data); var tcpPacket = p.Extract <TcpPacket>(); if (tcpPacket == null) { return; } log.Debug("passing packet to TcpConnectionManager"); tcpConnectionManager.ProcessPacket(rawPacket.Timeval, tcpPacket); }
/// <summary> /// Prints the time, length, src ip, src port, dst ip and dst port /// for each TCP/IP packet received on the network /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { var time = e.Header.Timeval.Date; var len = e.Data.Length; var rawPacket = e.GetPacket(); var packet = PacketDotNet.Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data); var tcpPacket = packet.Extract <PacketDotNet.TcpPacket>(); if (tcpPacket != null) { var ipPacket = (PacketDotNet.IPPacket)tcpPacket.ParentPacket; System.Net.IPAddress srcIp = ipPacket.SourceAddress; System.Net.IPAddress dstIp = ipPacket.DestinationAddress; int srcPort = tcpPacket.SourcePort; int dstPort = tcpPacket.DestinationPort; Console.WriteLine("{0}:{1}:{2},{3} Len={4} {5}:{6} -> {7}:{8}", time.Hour, time.Minute, time.Second, time.Millisecond, len, srcIp, srcPort, dstIp, dstPort); } }
private void LiveDevice_OnPacketArrival(object sender, PacketCapture e) { var packet = e.GetPacket(); if (IsWindows) { ReceivedPackets += BitConverter.ToInt64(packet.Data, 0); ReceivedBytes += BitConverter.ToInt64(packet.Data, 8); } else { ReceivedPackets++; ReceivedBytes += packet.PacketLength; } var args = new StatisticsEventArgs( this, packet.Timeval, ReceivedPackets, ReceivedBytes ); OnPcapStatistics?.Invoke(this, args); }
/// <summary> /// Handle incoming packets /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { var rawPacket = e.GetPacket(); var time = rawPacket.Timeval.Date; var len = rawPacket.Data.Length; Console.WriteLine("{0}:{1}:{2},{3} Len={4}", time.Hour, time.Minute, time.Second, time.Millisecond, len); // parse the incoming packet var packet = PacketDotNet.Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data); if (packet == null) { return; } var wol = packet.Extract <WakeOnLanPacket>(); if (wol.PayloadData != null) { PrintHex(wol.DestinationAddress.GetAddressBytes()); } }
/// <summary> /// Prints the time and length of each received packet /// </summary> private static void device_OnPacketArrival(object sender, PacketCapture e) { //var device = (ICaptureDevice)sender; // write the packet to the file var rawPacket = e.GetPacket(); captureFileWriter.Write(rawPacket); Console.WriteLine("Packet dumped to file."); if (rawPacket.LinkLayerType == PacketDotNet.LinkLayers.Ethernet) { var packet = PacketDotNet.Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data); var ethernetPacket = (EthernetPacket)packet; Console.WriteLine("{0} At: {1}:{2}: MAC:{3} -> MAC:{4}", packetIndex, rawPacket.Timeval.Date.ToString(), rawPacket.Timeval.Date.Millisecond, ethernetPacket.SourceHardwareAddress, ethernetPacket.DestinationHardwareAddress); packetIndex++; } }
internal void OnPacketArrival(object _, PacketCapture e) { PacketOperation((ILiveDevice)e.Device, (WinpkFilterHeader)e.Header, e.GetPacket().GetPacket()); }
void HandleDeviceOnPacketArrival(object sender, PacketCapture e) { Console.WriteLine("got packet " + e.GetPacket().ToString()); capturedPackets++; }
private void ProcessPcapPacket(object sender, PacketCapture e) { var packet = PacketDotNet.Packet.ParsePacket(e.GetPacket().LinkLayerType, e.GetPacket().Data); ProcessPacket(packet); }