Esempio n. 1
0
        public NetStats()
        {
            //Sets up the base for Send/Receive data calculations.
            tcpstat = ipgp.GetTcpIPv4Statistics();
            RECV_TOTAL = tcpstat.SegmentsReceived;
            SEND_TOTAL = tcpstat.SegmentsSent;

            //Configures the DataTable "cons" to hold four data columns.
            cons.Columns.Add("Process");
            cons.Columns.Add("ID");
            cons.Columns.Add("Local Port");
            cons.Columns.Add("Remote Address");
            cons.Columns.Add("Status");

            //Configuring DataTable "recv" to represent received data
            recv.Columns.Add("Time", Type.GetType("System.Int32"));
            recv.Columns.Add("Speed", Type.GetType("System.Int32"));
            recv.Rows.Add(0, 0);

            //Configuring DataTable "send" to represent received data
            send.Columns.Add("Time", Type.GetType("System.Int32"));
            send.Columns.Add("Speed", Type.GetType("System.Int32"));
            send.Rows.Add(0, 0);
        }
Esempio n. 2
0
        public void PopulateTable()
        {
            //# UPDATES CONNECTION TABLE #
            //Renews TCP connection information. Clears DataTable "cons," ready for a new set of data.
            tcpi = ipgp.GetActiveTcpConnections();
            tcpstat = ipgp.GetTcpIPv4Statistics();
            cons.Rows.Clear();

            //Creates a Row in the DataTable "cons" displaying the connections remote properties / status.
            foreach (TcpConnectionInformation t in tcpi)
            {
                try
                {
                    //Fetches process according to ports
                    Process pro = ipsh.GetProcessByPort(t.LocalEndPoint.Port);
                    cons.Rows.Add(new Object[] { pro.ProcessName, pro.Id, t.LocalEndPoint.Port, t.RemoteEndPoint.Address, t.State });
                }
                catch (Exception) { }
            }
            //# END CONNECTION TABLE #
            //# START RECV TABLE UPDATE #
            DataTable tmp = new DataTable();
            tmp.Columns.Add("Time", Type.GetType("System.Int32"));
            tmp.Columns.Add("Speed", Type.GetType("System.Int32"));

            tmp.Rows.Add(0,(tcpstat.SegmentsReceived - RECV_TOTAL));

            for (int a = 0; a < 59; a++)
            {
                try
                {
                    DataRow dr = recv.Rows[a];
                    int time = Convert.ToInt32(dr.ItemArray[0].ToString());
                    tmp.Rows.Add(new Object[] { time++, recv.Rows[a].ItemArray[1] });
                }
                catch (Exception) { break; }
            }
            RECV_TOTAL = tcpstat.SegmentsReceived;
            recv = tmp;
            //# END RECV TABLE UPDATE #
            //# START SEND TABLE UPDATE #
            DataTable snd = new DataTable();
            snd.Columns.Add("Time", Type.GetType("System.Int32"));
            snd.Columns.Add("Speed", Type.GetType("System.Int32"));

            snd.Rows.Add(0,(tcpstat.SegmentsSent - SEND_TOTAL));

            for (int a = 0; a < 59; a++)
            {
                try
                {
                    DataRow dr = send.Rows[a];
                    int time = Convert.ToInt32(dr.ItemArray[0].ToString());
                    snd.Rows.Add(new Object[] { time++, send.Rows[a].ItemArray[1] });
                }
                catch (Exception) { break; }
            }
            SEND_TOTAL = tcpstat.SegmentsSent;
            send = snd;
        }
Esempio n. 3
0
        public string GetReceived()
        {
            //Sets the amount of segments received to variable "rec"
            tcpstat = ipgp.GetTcpIPv4Statistics();
            long rec = tcpstat.SegmentsReceived;

            RECV_TOTAL = rec;

            //Returns value "rec" in a string formatted to KB, MB, or GB depending on the amount.
            return FormatBytes(rec);
        }
Esempio n. 4
0
        public string GetSent()
        {
            //Sets the amount of data sent to variable "sent"
            tcpstat = ipgp.GetTcpIPv4Statistics();
            long sent = tcpstat.SegmentsSent;

            //Returns amount of data sent formatted by method FormatBytes(long amt);
            return FormatBytes(sent);
        }
Esempio n. 5
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            System.Net.NetworkInformation.IPGlobalProperties ipgp = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
            System.Net.NetworkInformation.TcpStatistics      ts   = ipgp.GetTcpIPv4Statistics();
            System.Net.NetworkInformation.UdpStatistics      us   = ipgp.GetUdpIPv4Statistics();
            ArrayList al   = new ArrayList();
            ArrayList alus = new ArrayList();

            al.Add(ts);
            alus.Add(us);
            if (dataGridView6.DataSource == null || (dataGridView6.DataSource != null && !((ArrayList)dataGridView6.DataSource).Equals(alus)))
            {
                try
                {
                    dataGridView6.DataSource = alus;
                }
                catch { }
            }

            if (dataGridView5.DataSource == null || (dataGridView5.DataSource != null && !((ArrayList)dataGridView5.DataSource).Equals(al)))
            {
                try
                {
                    dataGridView5.DataSource = al;
                }
                catch { }
            }

            System.Net.IPEndPoint[] udplist = ipgp.GetActiveUdpListeners();
            if (dataGridView4.DataSource == null || (dataGridView4.DataSource != null && !((System.Net.IPEndPoint[])dataGridView4.DataSource).Equals(udplist)))
            {
                try
                {
                    dataGridView4.DataSource = udplist;
                }
                catch { }
            }
            System.Net.IPEndPoint[] tcplist = ipgp.GetActiveTcpListeners();
            if (dataGridView3.DataSource == null || (dataGridView3.DataSource != null && !((System.Net.IPEndPoint[])dataGridView3.DataSource).Equals(tcplist)))
            {
                try
                {
                    dataGridView3.DataSource = tcplist;
                }
                catch { }
            }
            System.Net.NetworkInformation.TcpConnectionInformation[] tci = ipgp.GetActiveTcpConnections();

            if (dataGridView2.DataSource == null || (dataGridView2.DataSource != null && !((System.Net.NetworkInformation.TcpConnectionInformation[])dataGridView2.DataSource).Equals(tci)))
            {
                try
                {
                    dataGridView2.DataSource = tci;
                }
                catch { }
            }


            FileInfo nfi = new FileInfo(strPath);

            if (nfi.LastWriteTime > fi.LastWriteTime)
            {
                RefreshLog();
            }
        }