private void ConnectSniffer_OnClick(object sender, RoutedEventArgs e)
 {
     if (sender == connectSniffer)
     {
         if (connectSniffer.IsChecked)
         {
             // can only attach sniffer to receiver if receiver object exists
             if (audysseyMultEQAvr == null)
             {
                 // create receiver instance
                 audysseyMultEQAvr = new AudysseyMultEQAvr();
                 // create adapter to interface MultEQAvr properties as if they were MultEQApp properties
                 audysseyMultEQAvrAdapter = new AudysseyMultEQAvrAdapter(audysseyMultEQAvr);
                 // data Binding to adapter
                 if ((tabControl.SelectedIndex == 0) && (audysseyMultEQApp == null))
                 {
                     this.DataContext = audysseyMultEQAvrAdapter;
                 }
                 if (tabControl.SelectedIndex == 1)
                 {
                     this.DataContext = audysseyMultEQAvr;
                 }
             }
             // sniffer must be elevated to capture raw packets
             if (!IsElevated())
             {
                 // we cannot create the sniffer...
                 connectSniffer.IsChecked = false;
                 // but we can ask the user to elevate the program!
                 RunAsAdmin();
             }
             else
             {
                 // onyl create sniffer if it not already exists
                 if (audysseyMultEQTcpSniffer == null)
                 {
                     // create sniffer attached to receiver
                     audysseyMultEQTcpSniffer = new AudysseyMultEQTcpSniffer(audysseyMultEQAvr, cmbInterfaceHost.SelectedItem.ToString(), cmbInterfaceClient.SelectedItem.ToString());
                 }
             }
         }
         else
         {
             if (audysseyMultEQTcpSniffer != null)
             {
                 audysseyMultEQTcpSniffer = null;
                 // if not interested in receiver then close connection and delete objects
                 if (connectReceiver.IsChecked == false)
                 {
                     this.DataContext         = null;
                     audysseyMultEQAvrAdapter = null;
                     audysseyMultEQAvr        = null;
                 }
                 // immediately clean up the object
                 GC.Collect();
                 GC.WaitForPendingFinalizers();
             }
         }
     }
 }
示例#2
0
            public AudysseyMultEQTcpSniffer(AudysseyMultEQAvr AudysseyMultEQAvr, string HostAddress, string ClientAddress)
            {
                audysseyMultEQAvr = AudysseyMultEQAvr;

                TcpHost   = new TcpIP(HostAddress, 0, 0);
                TcpClient = new TcpIP(ClientAddress, 1256, 0);

                //For sniffing the socket to capture the packets has to be a raw socket, with the
                //address family being of type internetwork, and protocol being IP
                try
                {
                    mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);

                    mainSocket.ReceiveBufferSize = 32768;

                    //Bind the socket to the selected IP address IPAddress.Parse("192.168.50.66")
                    mainSocket.Bind(new IPEndPoint(IPAddress.Parse(TcpHost.Address), TcpHost.Port));

                    //Set the socket  options
                    mainSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true);

                    mainSocket.IOControl(IOControlCode.ReceiveAll, new byte[] { (byte)ReceiveAll.RCVALL_ON, 0, 0, 0 }, new byte[] { (byte)ReceiveAll.RCVALL_ON, 0, 0, 0 });

                    //Start receiving the packets asynchronously
                    mainSocket.BeginReceive(packetData, 0, packetData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null);
                }
                catch (ObjectDisposedException)
                {
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "AudysseyMultEQTcpSniffer::TcpSniffer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
 private void ParseFileToAudysseyMultEQAvr(string FileName)
 {
     if (File.Exists(FileName))
     {
         string Serialized = File.ReadAllText(FileName);
         audysseyMultEQAvr = JsonConvert.DeserializeObject <AudysseyMultEQAvr>(Serialized, new JsonSerializerSettings {
         });
         if (audysseyMultEQAvrAdapter == null)
         {
             audysseyMultEQAvrAdapter = new AudysseyMultEQAvrAdapter(audysseyMultEQAvr);
         }
     }
 }
 private void ConnectReceiver_OnClick(object sender, RoutedEventArgs e)
 {
     if (sender == connectReceiver)
     {
         if (connectReceiver.IsChecked)
         {
             if (string.IsNullOrEmpty(cmbInterfaceClient.Text))
             {
                 System.Windows.MessageBox.Show("Please enter receiver IP address.");
             }
             else
             {
                 // if there is no Tcp client
                 if (audysseyMultEQAvrTcp == null)
                 {
                     // create receiver instance
                     if (audysseyMultEQAvr == null)
                     {
                         audysseyMultEQAvr = new AudysseyMultEQAvr();
                     }
                     // create receiver tcp instance
                     audysseyMultEQAvrTcp = new AudysseyMultEQAvrTcp(audysseyMultEQAvr, cmbInterfaceClient.Text);
                     // create adapter to interface MultEQAvr properties as if they were MultEQApp properties
                     if (audysseyMultEQAvrAdapter == null)
                     {
                         audysseyMultEQAvrAdapter = new AudysseyMultEQAvrAdapter(audysseyMultEQAvr);
                     }
                     // data Binding to adapter
                     if ((tabControl.SelectedIndex == 0) && (audysseyMultEQApp == null))
                     {
                         this.DataContext = audysseyMultEQAvrAdapter;
                     }
                     if (tabControl.SelectedIndex == 1)
                     {
                         this.DataContext = audysseyMultEQAvr;
                     }
                 }
                 audysseyMultEQAvrTcp.Connect();
                 // attach sniffer
                 if (connectSniffer.IsChecked)
                 {
                     // sniffer must be elevated to capture raw packets
                     if (!IsElevated())
                     {
                         // we cannot create the sniffer...
                         connectSniffer.IsChecked = false;
                         // but we can ask the user to elevate the program!
                         RunAsAdmin();
                     }
                     else
                     {
                         if (audysseyMultEQTcpSniffer == null)
                         {
                             audysseyMultEQTcpSniffer = new AudysseyMultEQTcpSniffer(audysseyMultEQAvr, cmbInterfaceHost.SelectedItem.ToString(), cmbInterfaceClient.SelectedItem.ToString());
                         }
                     }
                 }
             }
         }
         else
         {
             audysseyMultEQAvrAdapter = null;
             audysseyMultEQAvrTcp     = null;
             audysseyMultEQAvr        = null;
             // immediately clean up the object
             GC.Collect();
             GC.WaitForPendingFinalizers();
             this.DataContext = null;
         }
     }
 }
示例#5
0
 public AudysseyMultEQAvrTcp(AudysseyMultEQAvr audysseyMultEQAvr, string ClientAddress)
 {
     _audysseyMultEQAvr = audysseyMultEQAvr;
     TcpClient          = new TcpIP(ClientAddress, 1256, 5000);
 }
 public AudysseyMultEQAvrAdapter(AudysseyMultEQAvr audysseyMultEQAvr)
 {
     _audysseyMultEQAvr = audysseyMultEQAvr;
     // bind parent to nofify property changed
     audysseyMultEQAvr.PropertyChanged += _PropertyChanged;
 }