Esempio n. 1
0
        int GetOpenSockets()
        {
            int count = 0;
            int port  = Settings.Instance.PortFilter;

            foreach (var entry in ManagedNetstat.GetTcp())
            {
                if (entry.RemoteEndpoint.Port != port)
                {
                    continue;
                }
                if (entry.State != TcpState.Established)
                {
                    continue;
                }
                count++;
            }
            return(count);
        }
Esempio n. 2
0
        void Populate()
        {
            section.Clear();
            var entries = ManagedNetstat.GetTcp();

            foreach (var entry in entries)
            {
                if (!Filter(entry))
                {
                    continue;
                }
                var text    = string.Format("{0} - {1} - {2}", entry.LocalEndpoint, entry.RemoteEndpoint, entry.State);
                var element = new StyledStringElement(text);
                element.Font = UIFont.SystemFontOfSize(12.0f);
                if (!displayedEntries.ContainsKey(entry))
                {
                    displayedEntries.Add(entry, DateTime.UtcNow);
                    element.BackgroundColor = UIColor.Red;
                }
                else
                {
                    var age = DateTime.UtcNow - displayedEntries [entry];
                    if (age < TimeSpan.FromSeconds(3))
                    {
                        element.BackgroundColor = UIColor.Yellow;
                    }
                }
                section.Add(element);
            }
            var oldEntries = displayedEntries.Keys.ToList();

            foreach (var old in oldEntries)
            {
                if (!entries.Contains(old))
                {
                    displayedEntries.Remove(old);
                }
            }
        }