void SelectedInterface_WlanNotification(Wlan.WlanNotificationData notifyData)
 {
     if (notifyData.notificationSource == Wlan.WlanNotificationSource.MSM)
     {
         SelectedInterface.RefreshConnected();
     }
 }
 void SelectedInterface_WlanConnectionNotification(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData)
 {
     if (owner != null && owner.IsVisible)
     {
         SelectedInterface?.UpdateInformation();
         UpdateNetworkSignalQuality();
     }
 }
 void SelectedInterface_WlanNotification(Wlan.WlanNotificationData notifyData)
 {
     if (owner != null && owner.IsVisible && notifyData.notificationSource == Wlan.WlanNotificationSource.MSM)
     {
         SelectedInterface?.UpdateInformation();
         UpdateNetworkSignalQuality();
     }
 }
        private void Owner_IsVisibleChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
        {
            if (owner.IsVisible)
            {
                selectedInterface.interFace.WlanConnectionNotification += SelectedInterface_WlanConnectionNotification;
                selectedInterface.interFace.WlanNotification           += SelectedInterface_WlanNotification;
                selectedInterface.interFace.WlanReasonNotification     += SelectedInterface_WlanReasonNotification;

                SelectedInterface?.UpdateInformation();
            }
            else
            {
                selectedInterface.interFace.WlanConnectionNotification -= SelectedInterface_WlanConnectionNotification;
                selectedInterface.interFace.WlanNotification           -= SelectedInterface_WlanNotification;
                selectedInterface.interFace.WlanReasonNotification     -= SelectedInterface_WlanReasonNotification;
            }
        }
 void SelectedInterface_WlanConnectionNotification(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData)
 {
     SelectedInterface.RefreshConnected();
 }
 void SelectedInterface_WlanReasonNotification(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode)
 {
     SelectedInterface.RefreshConnected();
 }
Exemplo n.º 7
0
        public void PacketHandler()
        {
            Packet packet;

            try
            {
                IsBusy = true;
                cts    = new CancellationTokenSource();
                CancellationToken token = cts.Token;

                // Open the device
                communicator = SelectedInterface.Open(65536,                                  // 65536 guarantees that the whole packet will be captured on all the link layers
                                                      PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                                      1000);                                  // read timeout

                if (!string.IsNullOrEmpty(trafficFilter))
                {
                    communicator.SetFilter(trafficFilter);
                }

                do
                {
                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);
                    switch (result)
                    {
                    case PacketCommunicatorReceiveResult.Timeout:
                        // Timeout elapsed
                        continue;

                    case PacketCommunicatorReceiveResult.Ok:
                        if (packet.Ethernet.EtherType == EthernetType.IpV4)
                        {
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                packets.Add(packet);
                                StatHandler.UpdateStats(packet);
                            });
                        }
                        break;

                    default:
                        throw new InvalidOperationException("PacketCommunicator InvalidOperationException");
                    }
                } while (!token.IsCancellationRequested);
            }
            catch (Exception ex)
            {
                MessageBox.Show("A handled exception occurred: " + ex.Message, "Tcp/Ip sniffer",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            finally
            {
                communicator.Break();
                communicator.Dispose();
                communicator = null;

                cts.Dispose();
                cts    = null;
                IsBusy = false;
            }
        }