Пример #1
0
        public async Task <bool> RunScan(CancellationTokenSource token, PacketDevice pd)
        {
            return(await Task.Run(async() =>
            {
                using (var communicator = pd.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
                {
                    using (var filter = communicator.CreateFilter("ip and udp"))
                    {
                        communicator.SetFilter(filter);
                    }

                    var packetTable = new PacketTable();

                    do
                    {
                        Packet packet;

                        var result = communicator.ReceivePacket(out packet);

                        switch (result)
                        {
                        case PacketCommunicatorReceiveResult.Ok:
                            if (packet.IpV4 == null)
                            {
                                continue;
                            }

                            var ip = packet.Ethernet.IpV4;
                            var udp = ip.Udp;

                            var packetItem = new PacketLogItem
                            {
                                Destination = ip.Destination.ToString(),
                                DestinationPort = udp.DestinationPort,
                                Size = packet.Length,
                                Source = ip.Source.ToString(),
                                SourcePort = udp.SourcePort,
                                TimeStamp = DateTime.Now
                            };

                            OnNewPacketEntry(packetItem);

                            await packetTable.WritePacketAsync(packetItem);

                            break;
                        }

                        if (token.IsCancellationRequested)
                        {
                            return true;
                        }
                    } while (true);

                    return true;
                }
            }, token.Token));
        }
Пример #2
0
 public async Task <bool> WritePacketAsync(PacketLogItem packetItem)
 {
     return(await WriteAsync(new Packets
     {
         Size = packetItem.Size,
         DestinationPort = packetItem.DestinationPort,
         DestinationIP = packetItem.Destination,
         SourceIP = packetItem.Source,
         SourtPort = packetItem.SourcePort,
         Timestamp = packetItem.TimeStamp
     }));
 }
Пример #3
0
        private void Scanner_NewPacketEntry(object sender, PacketLogItem e)
        {
            Packets.Enqueue(e);

            Packets = new ConcurrentQueue <PacketLogItem>(Packets);
        }
Пример #4
0
 public void OnNewPacketEntry(PacketLogItem e)
 {
     NewPacketEntry?.Invoke(null, e);
 }