Beispiel #1
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
            MyAPI.GetTcpStats();
            string m_algo = "";

            switch (MyAPI.TcpStats.dwRtoAlgorithm)
            {
            case 1: m_algo = "Other"; break;

            case 2: m_algo = "Constant Time-out"; break;

            case 3: m_algo = "MIL-STD-1778 Appendix B"; break;

            case 4: m_algo = "Van Jacobson's Algorithm"; break;
            }
            this.listBox1.Items.Add(string.Format("{0} : {1}", "RtoAlgorithm", m_algo));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "RtoMin", MyAPI.TcpStats.dwRtoMin.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "RtoMax", MyAPI.TcpStats.dwRtoMax.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Max Connection", MyAPI.TcpStats.dwMaxConn.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Active Open Connection", MyAPI.TcpStats.dwActiveOpens.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Passive Open Connection", MyAPI.TcpStats.dwPassiveOpens.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Attempte Fail", MyAPI.TcpStats.dwAttemptFails.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Estabished connection that have been reset", MyAPI.TcpStats.dwEstabResets.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Current estabished connection", MyAPI.TcpStats.dwCurrEstab.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "In Segments", MyAPI.TcpStats.dwInSegs.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Out Segement", MyAPI.TcpStats.dwOutSegs.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "Segement Retransmitted", MyAPI.TcpStats.dwRetransSegs.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "InErrors", MyAPI.TcpStats.dwInErrs.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "number of segments transmitted with the reset flag set", MyAPI.TcpStats.dwRetransSegs.ToString()));
            this.listBox1.Items.Add(string.Format("{0} : {1}", "number of connections", MyAPI.TcpStats.dwNumConns.ToString()));
        }
Beispiel #2
0
        string doLog()
        {
            DateTime dt    = DateTime.Now;
            string   dtStr = dt.ToShortDateString() + ", " + dt.ToShortTimeString();

            if (g_iphlp == null)
            {
                g_iphlp = new IpHlpApidotnet.IPHelper();
            }

            string sOut = "";

            g_iphlp.GetTcpConnexions();
            sOut += "======= TCP table ========\r\n" + "local".PadRight(28) + "remote\r\n";
            foreach (IpHlpApidotnet.MIB_TCPROW stat in g_iphlp.TcpConnexion.table)
            {
                sOut += IpHlpApidotnet.IPHelper.dump_MIB_TCPROW(stat) + "\r\n";
            }

            g_iphlp.GetUdpConnexions();
            sOut += "======= UDP table ========\r\n";
            foreach (IpHlpApidotnet.MIB_UDPROW stat in g_iphlp.UdpConnexion.table)
            {
                sOut += IpHlpApidotnet.IPHelper.dump_MIB_UDPROW(stat) + "\r\n";
            }

            g_iphlp.GetTcpStats();
            sOut += "======= TCP statistics ========\r\n";
            sOut += IpHlpApidotnet.IPHelper.dump_MIB_TCPSTATS(g_iphlp.TcpStats) + "\r\n";

            g_iphlp.GetUdpStats();
            sOut += "======= UDP statistics ========\r\n";
            sOut += IpHlpApidotnet.IPHelper.dump_MIB_UDPSTATS(g_iphlp.UdpStats) + "\r\n";


            AdapterInfo.AdaptersInfo aInfo = new AdapterInfo.AdaptersInfo();
            sOut += "======= Adapter infos ==========\r\n";
            foreach (AdapterInfo.IP_ADAPTER_INFO info in aInfo._adapterList)
            {
                sOut += info.Index.ToString() + ": " + info.AdapterName + ", " + info.CurrentIpAddress.IpAddress.String + "\r\n";
            }

            g_iphlp.getRoutingTable();
            sOut += "======= Route entries ==========\r\n";
            //                                   1         2         3         4         5         6         7         8
            //                          12345678901234567890123456789012345678901234567890123456789012345678901234567890123
            sOut += "Network Destination        Netmask          Gateway          Interface     Metric\r\n";
            foreach (IpHlpApidotnet.IPHlpAPI32Wrapper.MIB_IPFORWARDROW row in g_iphlp._routeEntry)
            {
                sOut += g_iphlp.dumpRouteEntry(row) + "\r\n";
            }

            string sFile = "\\netstat.log";

            try
            {
                StreamWriter sw = new StreamWriter(sFile, true, Encoding.UTF8, 2000);
                sw.WriteLine(dtStr + " #################\r\n" + sOut);
                sw.Flush();
                sw.Close();
                System.Diagnostics.Debug.WriteLine("logged to file");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in writeLog: " + ex.Message);
            }
            return(sOut);
        }