Exemplo n.º 1
0
        private void AddOrInsertItem(TCPUDPConnection conn, int Position)
        {
            string state = String.Empty;

            if (conn.Protocol == Protocol.TCP)
            {
                state = conn.State;
            }
            ListViewItem lvi = null;

            if (Position != -1)
            {
                lvi = listView1.Items.Insert(Position, state);
            }
            else
            {
                lvi = listView1.Items.Add(state);
            }
            lvi.SubItems.Add(conn.LocalAddress);// lvi.SubItems.Add(conn.Local.ToString());
            if (conn.Protocol == Protocol.TCP)
            {
                lvi.SubItems.Add(conn.RemoteAddress);//lvi.SubItems.Add(conn.Remote.ToString());
            }
            else
            {
                lvi.SubItems.Add("");
            }
            lvi.SubItems.Add(conn.PID.ToString());
            lvi.SubItems.Add(conn.ProcessName);
            lvi.SubItems.Add(conn.Protocol.ToString());
            tsGrid1.Text = "Grid1 items: " + listView1.Items.Count.ToString();
        }
Exemplo n.º 2
0
 void conns_ItemAdded(object sender, TCPUDPConnection item)
 {
     try
     {
         this.Invoke(m_AddNewItem, item);
     }
     catch {}
 }
Exemplo n.º 3
0
 void conns_ItemInserted(object sender, TCPUDPConnection item, int Position)
 {
     try
     {
         this.Invoke(m_InsertItem, item, Position);
     }
     catch { }
 }
Exemplo n.º 4
0
 void conns_ItemChanged(object sender, TCPUDPConnection item, int Position)
 {
     try
     {
         this.Invoke(m_ChangedItem, item, Position);
     }
     catch { }
 }
Exemplo n.º 5
0
        private void ChangeItem(TCPUDPConnection conn, int Position)
        {
            string state = String.Empty;

            if (conn.Protocol == Protocol.TCP)
            {
                state = conn.State;
            }
            ListViewItem lvi = listView1.Items[Position];

            lvi.SubItems["colStateUpper"].Text   = state;
            lvi.SubItems["colPIDUpper"].Text     = conn.PID.ToString();
            lvi.SubItems["colProcessUpper"].Text = conn.ProcessName;
        }
Exemplo n.º 6
0
        private void Row_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            // Check we have double clicked on a row in the DataGrid
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row == null)
            {
                return;
            }

            //Get connection represented by row
            TCPUDPConnection conn = row.Item as TCPUDPConnection;

            if (conn != null)
            {
                //Update detailed view
                UpdateDetailView(conn);
            }
        }
Exemplo n.º 7
0
        // Displays details of a selected connection
        private void UpdateDetailView(TCPUDPConnection conn)
        {
            PromptText.Visibility = Visibility.Hidden;

            // Clear all text
            ProtocolText.Text   = string.Empty;
            StatusText.Text     = string.Empty;
            LocalAddrText.Text  = string.Empty;
            RemoteAddrText.Text = string.Empty;
            PIDText.Text        = string.Empty;
            PNameText.Text      = string.Empty;
            PPathText.Text      = string.Empty;
            CountryText.Text    = string.Empty;
            RegionText.Text     = string.Empty;
            WhoisText.Text      = string.Empty;

            ProtocolText.Inlines.Add(new Bold(new Run("Protocol ")));
            ProtocolText.Inlines.Add(conn.Protocol.ToString());

            StatusText.Inlines.Add(new Bold(new Run("Status ")));
            StatusText.Inlines.Add(conn.State);

            LocalAddrText.Inlines.Add(new Bold(new Run("Local address ")));
            LocalAddrText.Inlines.Add(conn.LocalAddress);

            RemoteAddrText.Inlines.Add(new Bold(new Run("Remote address ")));
            RemoteAddrText.Inlines.Add(conn.RemoteAddress);

            PIDText.Inlines.Add(new Bold(new Run("Process ID ")));
            PIDText.Inlines.Add(conn.PID.ToString());

            PNameText.Inlines.Add(new Bold(new Run("Process name ")));
            PNameText.Inlines.Add(conn.ProcessName);

            PPathText.Inlines.Add(new Bold(new Run("Process path ")));
            PPathText.Inlines.Add(conn.ProcessPath);


            // Allow WHOIS lookup for valid IPs that begin with a number
            String ip = conn.RemoteAddress;

            if (IsIpAddress(ip))
            {
                // Look up information about IP in database

                try
                {
                    var city = _reader.City(GetIpWithoutPort(ip));
                    CountryText.Inlines.Add(new Bold(new Run("Country ")));
                    CountryText.Inlines.Add(city.Country.Name);

                    RegionText.Inlines.Add(new Bold(new Run("Region ")));
                    RegionText.Inlines.Add(city.MostSpecificSubdivision.Name);
                }
                catch (MaxMind.GeoIP2.Exceptions.AddressNotFoundException)
                {
                    //CountryText.Inlines.Add("Unknown/Not applicable");
                }
                catch (System.ArgumentNullException)
                {
                    // Do nothing
                }

                // Display WHOIS link
                Hyperlink link = new Hyperlink();
                link.Inlines.Add("Perform WHOIS Lookup");
                link.NavigateUri      = new Uri("https://who.is/whois-ip/ip-address/" + GetIpWithoutPort(ip));
                link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(Hyperlink_RequestNavigate);
                WhoisText.Inlines.Add(link);
            }
        }
Exemplo n.º 8
0
 private void DeleteItem(TCPUDPConnection conn, int Position)
 {
     listView1.Items.RemoveAt(Position);
     tsGrid1.Text = "Grid1 items: " + listView1.Items.Count.ToString();
 }
Exemplo n.º 9
0
 private void AddItem(TCPUDPConnection conn)
 {
     AddOrInsertItem(conn, -1);
 }