diff --git a/fastnetmon.cpp b/fastnetmon.cpp index 7b26627f5..d1229ae96 100644 --- a/fastnetmon.cpp +++ b/fastnetmon.cpp @@ -120,12 +120,18 @@ bool DEBUG = 0; // flag about dumping all packets to console bool DEBUG_DUMP_ALL_PACKETS = false; -// Period for recounting pps/traffic +// Period for update screen for console version of tool unsigned int check_period = 3; // Standard ban time in seconds for all attacks but you can tune this value int standard_ban_time = 1800; +// We calc average pps/bps for this time +double average_calculation_amount = 15; + +// Enable or disable average traffic counter +bool print_average_traffic_counts = false; + #ifdef PCAP // Enlarge receive buffer for PCAP for minimize packet drops unsigned int pcap_buffer_size_mbytes = 10; @@ -219,7 +225,9 @@ typedef attack_details banlist_item; typedef pair subnet; // main data structure for storing traffic and speed data for all our IPs -typedef struct { +class map_element { +public: + map_element() : in_bytes(0), out_bytes(0), in_packets(0), out_packets(0), tcp_in_packets(0), tcp_out_packets(0), tcp_in_bytes(0), tcp_out_bytes(0), udp_in_packets(0), udp_out_packets(0), udp_in_bytes(0), udp_out_bytes(0), in_flows(0), out_flows(0) {} unsigned int in_bytes; unsigned int out_bytes; unsigned int in_packets; @@ -239,7 +247,7 @@ typedef struct { unsigned int in_flows; unsigned int out_flows; -} map_element; +}; // struct for save per direction and per protocol details for flow typedef struct { @@ -334,6 +342,9 @@ map FlowCounter; // Struct for string speed per IP map_for_counters SpeedCounter; +// Struct for storing average speed per IP for specified interval +map_for_counters SpeedCounterAverage; + #ifdef GEOIP map_for_counters GeoIpCounter; #endif @@ -604,18 +615,30 @@ string draw_table(map_for_counters& my_map_packets, direction data_direction, bo // flow per second unsigned int flows = 0; + unsigned int pps_average = 0; + unsigned int bps_average = 0; + // Create polymorphic pps, byte and flow counters if (data_direction == INCOMING) { pps = SpeedCounter[client_ip].in_packets; bps = SpeedCounter[client_ip].in_bytes; + + pps_average = SpeedCounterAverage[client_ip].in_packets; + bps_average = SpeedCounterAverage[client_ip].in_bytes; + flows = SpeedCounter[client_ip].in_flows; } else if (data_direction == OUTGOING) { pps = SpeedCounter[client_ip].out_packets; bps = SpeedCounter[client_ip].out_bytes; + + pps_average = SpeedCounterAverage[client_ip].out_packets; + bps_average = SpeedCounterAverage[client_ip].out_bytes; + flows = SpeedCounter[client_ip].out_flows; } double mbps = (double)bps/1024/1024*8; + double mbps_average = (double)bps_average/1024/1024*8; // Set one number after comma for double output_buffer< 0 ? " *banned* " : ""; // We use setw for alignment - output_buffer - <= 0) {