private void generateReportButton_Click(object sender, EventArgs e) { // get the filepath string filepath = BandwidthAnalyzer.GetDBPath() + Path.DirectorySeparatorChar + BandwidthAnalyzer.DB_NAME; // process the file line by line based on the selected filters try { int packetsOut = 0; int packetsIn = 0; BandwidthCounter bandwidthOut = new BandwidthCounter(); BandwidthCounter bandwidthIn = new BandwidthCounter(); if (File.Exists(filepath)) { // get the filter parameters long startTime = startDatePicker.Value.Ticks; long endTime = endDatePicker.Value.Ticks; DateTime accessTime = File.GetLastAccessTime(filepath); try { SQLiteConnection db = new SQLiteConnection(); db.ConnectionString = new SQLiteConnectionStringBuilder() { {"Data Source", BandwidthAnalyzer.GetDBPath() + Path.DirectorySeparatorChar + "connection_db.db"}, {"Version", "3"}, {"FailIfMissing", "False"} }.ConnectionString; db.Open(); CheckBox[] checkboxes = new CheckBox[] { tcpCheckbox, udpCheckbox, eethCheckbox, ethernetCheckbox, ipCheckbox, icmpv6Checkbox, arpCheckbox, icmpCheckbox, dnsCheckbox, dhcpCheckbox, snmpCheckbox }; string protocolList = ""; foreach (CheckBox checkbox in checkboxes) { if (checkbox.Checked) protocolList += ",'" + matchCheckbox(checkbox) + "'"; } protocolList = protocolList.Remove(0, 1); string timeFilter = ""; if (timestampCheckbox.Checked) { timeFilter = "timestamp between " + startTime + " and " + endTime; } string query = "select * from connection_log where protocol in (" + protocolList + ")" + timeFilter; SQLiteCommand command = new SQLiteCommand(query, db); using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { bool outgoing = reader.GetBoolean(0); long timestamp = reader.GetInt64(1); string ip = reader.GetString(2); uint size = (uint) reader.GetInt32(3); string protocol = reader.GetString(4); if (outgoing) { ++packetsOut; bandwidthOut.AddBits(size); } else { ++packetsIn; bandwidthIn.AddBits(size); } } } db.Close(); MessageBox.Show("Analysis of connections logged as of " + accessTime + "\nTotal Packets Sent: " + packetsOut + "\nTotal Packets Received: " + packetsIn + "\nTotal Outgoing Bandwidth: " + bandwidthOut.ToString() + "\nTotal Incoming Bandwidth: " + bandwidthIn.ToString()); } catch (Exception ex) { PassThru.LogCenter.WriteErrorLog(ex); } } else { MessageBox.Show("No data available. This module needs to be enabled in " + "order for it to collect data to analyze."); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
public AdapterInfo(string P, string N, NetworkInterface NI, BandwidthCounter In, BandwidthCounter Out, NetworkAdapter na) { pointer = P; this.deviceName = N; ni = na.InterfaceInformation; this.In = In; this.Out = Out; this.na = na; }