Ejemplo n.º 1
0
 private void metroButton2_Click(object sender, EventArgs e)
 {
     this.listBox1.Items.Clear();
     MyAPI.GetUdpStats();
     this.listBox1.Items.Add(string.Format("{0} : {1}", "In Datagrams", MyAPI.UdpStats.dwInDatagrams.ToString()));
     this.listBox1.Items.Add(string.Format("{0} : {1}", "Out Datagrams", MyAPI.UdpStats.dwOutDatagrams.ToString()));
     this.listBox1.Items.Add(string.Format("{0} : {1}", "In Errors", MyAPI.UdpStats.dwInErrors.ToString()));
     this.listBox1.Items.Add(string.Format("{0} : {1}", "No Ports", MyAPI.UdpStats.dwNoPorts.ToString()));
     this.listBox1.Items.Add(string.Format("{0} : {1}", "Num Address", MyAPI.UdpStats.dwNumAddrs.ToString()));
 }
Ejemplo n.º 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);
        }