private void Used_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            //allow to edit ports and save that
            InterfaceClass li = null;
            bool           removeInterfaceFromUsed = false;

            foreach (var iface in UsedInterfaces)
            {
                if (iface.ToString().Equals(LBUsed.SelectedItem.ToString()))
                {
                    li = iface;
                    if (LBUsed.SelectedItem != null)
                    {
                        BaseWindow editInterfaceWindow = new BaseWindow()
                        {
                            Owner = MyBaseWindow, MaxHeight = 75, Width = 300
                        };
                        EditInterface editInterface = new EditInterface(ref li, ref editInterfaceWindow);
                        editInterfaceWindow.ClientArea.Content = editInterface;

                        editInterfaceWindow.Closing += new CancelEventHandler(delegate(object o, System.ComponentModel.CancelEventArgs cancelEventArgs) {
                            iface.Ports             = editInterface.getPorts();
                            removeInterfaceFromUsed = !(bool)editInterface.checkBox.IsChecked;
                        });
                        editInterfaceWindow.ShowDialog();
                    }
                    break;
                }
            }
            if (removeInterfaceFromUsed && li != null)
            {
                AvaliableInterfaces.Add(li);
                UsedInterfaces.Remove(li);
            }
        }
Example #2
0
        public EditInterface(ref InterfaceClass interfaceObj, ref BaseWindow MyBaseWindow)
        {
            InitializeComponent();
            this.MyBaseWindow  = MyBaseWindow;
            MyBaseWindow.Title = "Edycja portów";

            MyBaseWindow.SizeChanged += MyBaseWindow_SizeChanged;

            this.interfaceObj = interfaceObj;
            strIP.Text        = interfaceObj.Addres;
            strPort.Text      = interfaceObj.Ports;
        }
Example #3
0
        private void addNewInterface(InterfaceClass interfaceObj)
        {
            CaptureDeviceList _devices = CaptureDeviceList.Instance;

            ICaptureDevice device = null;

            // differentiate based upon types
            foreach (ICaptureDevice dev in _devices)
            {
                if (dev.ToString().Contains(interfaceObj.Addres))
                {
                    device = dev;
                    device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
                    devices.Add(device);
                    device.Open();
                    device.StartCapture();

                    break;
                }
            }
        }
Example #4
0
        private void BackgroundThread()
        {
            while (!BackgroundThreadStop)
            {
                bool shouldSleep = true;

                lock (QueueLock) {
                    if (PacketQueue.Count != 0)
                    {
                        shouldSleep = false;
                    }
                }

                if (shouldSleep)
                {
                    Thread.Sleep(250);
                }
                else // should process the queue
                {
                    List <RawCapture> queue;
                    lock (QueueLock) {
                        // swap queues, giving the capture callback a new one
                        queue       = PacketQueue;
                        PacketQueue = new List <RawCapture>();
                    }

                    Console.WriteLine("BackgroundThread: Queue.Count is {0}", queue.Count);

                    foreach (var packet in queue)
                    {
                        var _packet = PacketDotNet.Packet.ParsePacket(packet.LinkLayerType, packet.Data);

                        if (_packet is PacketDotNet.EthernetPacket)
                        {
                            var ip = (PacketDotNet.IpPacket)_packet.Extract(typeof(PacketDotNet.IpPacket));
                            if (ip != null)
                            {
                                bool           filterOut    = true;
                                InterfaceClass tmpInterface = null;
                                foreach (InterfaceClass iFace in UsedInterfaces)
                                {
                                    if (iFace.Addres.Equals(ip.DestinationAddress.ToString()))
                                    {
                                        filterOut    = false;
                                        tmpInterface = iFace;
                                        break;
                                    }
                                }
                                if (filterOut == false)
                                {
                                    filterOut = true;
                                    var tcp = (PacketDotNet.TcpPacket)_packet.Extract(typeof(PacketDotNet.TcpPacket));
                                    if (tcp != null)
                                    {
                                        if (tmpInterface.isPortValid(tcp.DestinationPort))
                                        {
                                            string             phrase  = MainWindow.SearchPhrase;
                                            LevenshteinMatches matches = Encoding.UTF8.GetString(tcp.PayloadData).Levenshtein(phrase, mode: window.snifferMode);
                                            if (matches.hasMatches)
                                            {
                                                window.AddTextToNetworkBox(tmpInterface.Addres + ":" + tcp.DestinationPort + "\n");
                                                window.AddTextToNetworkBox(matches);
                                            }
                                        }
                                    }
                                    var udp = (PacketDotNet.UdpPacket)_packet.Extract(typeof(PacketDotNet.UdpPacket));
                                    if (udp != null)
                                    {
                                        if (tmpInterface.isPortValid(udp.DestinationPort))
                                        {
                                            string             phrase  = MainWindow.SearchPhrase;
                                            LevenshteinMatches matches = Encoding.UTF8.GetString(udp.PayloadData).Levenshtein(phrase, mode: window.snifferMode);
                                            if (matches.hasMatches)
                                            {
                                                window.AddTextToNetworkBox(tmpInterface.Addres + ":" + udp.DestinationPort + "\n");
                                                window.AddTextToNetworkBox(matches);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }