示例#1
0
 private void Menu_StopCapture(object sender, Avalonia.Interactivity.RoutedEventArgs e)
 {
     mnuStopCapture.IsEnabled = false;
     if (sniffer != null)
     {
         sniffer.ReceivedPacket -= Sniffer_ReceivedPacket;
         sniffer.Dispose();
     }
     sniffer = null;
 }
示例#2
0
        private void Sniffer_ReceivedPacket(NetworkSniffer sniffer, PCapPacket packet)
        {
            if (DataPackets == null)
            {
                DataPackets = new List <PCapPacket>();
            }
            if (packet.PacketType != PCapPacketType.Other && !(packet.IsBaseIpProtocol ||
                                                               (packet.PortSource == 0 && packet.PortDestination == 0) ||
                                                               packet.Data == null ||
                                                               packet.Data.Length == 0))
            {
                lock (DataPacketsLock)
                {
                    DataPackets.Add(packet);
                }

                if (SearchStats.IsSearchPacket(packet))
                {
                    searchStats.Add(packet);
                }

                // Does the new packet match the filter?
                var filter = txtFilter.Text?.ToLower() ?? "";
                if (packet.Source.Contains(filter) ||
                    packet.Destination.Contains(filter) ||
                    packet.PacketType.ToString().ToLower().Contains(filter) ||
                    packet.PacketNumber.ToString().Contains(filter))
                {
                    Avalonia.Threading.Dispatcher.UIThread.Post(() =>
                    {
                        var item = new PacketListItem
                        {
                            PacketNumber      = packet.PacketNumber,
                            PacketSource      = packet.Source,
                            PacketDestination = packet.Destination,
                            PacketProtocol    = packet.PacketType.ToString(),
                            PacketLength      = packet.Data.Length,
                            Packet            = packet,
                            Foreground        = Colorize(packet.Data)
                        };
                        item.Click += Item_Click;
                        scrollPanel.Children.Add(item);
                    });
                }
            }
        }
示例#3
0
        private void Menu_Capture(object sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            var capture = new CaptureWindow();

            capture.ShowDialog <string>(this).ContinueWith(result =>
            {
                if (result.Result == null)
                {
                    return;
                }
                if (sniffer != null)
                {
                    sniffer.ReceivedPacket -= Sniffer_ReceivedPacket;
                    sniffer.Dispose();
                }
                Avalonia.Threading.Dispatcher.UIThread.Post(() =>
                {
                    searchStats.Clear();

                    try
                    {
                        sniffer = new NetworkSniffer(result.Result);
                    }
                    catch (System.Net.Sockets.SocketException ex)
                    {
                        if (sniffer != null)
                        {
                            sniffer.Dispose();
                        }
                        sniffer = null;

                        //Console.WriteLine(ex.ToString());
                        if (ex.NativeErrorCode == 10049)//  ex.Message == "The requested address is not valid in its context."
                        {
                            var dlg = new AdminRightsRequired {
                                Message = "Impossible to bind to this network interface.", Title = "Wrong network interface"
                            };
                            dlg.ShowDialog(this);
                        }
                        else if (ex.NativeErrorCode == 10013)
                        {
                            var dlg = new AdminRightsRequired();
                            dlg.ShowDialog(this);
                        }
                        else
                        {
                            var dlg = new AdminRightsRequired {
                                Message = ex.Message, Title = "Error while binding"
                            };
                            dlg.ShowDialog(this);
                        }
                    }
                    if (sniffer != null)
                    {
                        sniffer.ReceivedPacket += Sniffer_ReceivedPacket;
                        DataPackets             = new List <PCapPacket>();
                        ShowDataPacket();
                        mnuStopCapture.IsEnabled = true;
                    }
                });
            });
        }