Просмотр исходного кода

Fix #3: Consider sent and received packets for the PPS

Carlos Garcia 7 лет назад
Родитель
Сommit
11d370a071
2 измененных файлов с 16 добавлено и 1 удалено
  1. 3 1
      code/Attack/PortscanAttack.py
  2. 13 0
      code/ID2TLib/Statistics.py

+ 3 - 1
code/Attack/PortscanAttack.py

@@ -54,7 +54,9 @@ class PortscanAttack(BaseAttack.BaseAttack):
         self.add_param_value(Param.PORT_ORDER_DESC, 'False')
         self.add_param_value(Param.MAC_SOURCE, 'macAddress(ipAddress=' + most_used_ipAddress + ')')
         self.add_param_value(Param.MAC_DESTINATION, 'A0:1A:28:0B:62:F4')
-        self.add_param_value(Param.PACKETS_PER_SECOND, self.statistics.get_pps_sent(most_used_ipAddress))
+        self.add_param_value(Param.PACKETS_PER_SECOND,
+                             (self.statistics.get_pps_sent(most_used_ipAddress) +
+                              self.statistics.get_pps_received(most_used_ipAddress)) / 2)
         self.add_param_value(Param.INJECT_AT_TIMESTAMP, '1410733342')  # Sun, 14 Sep 2014 22:22:22 GMT
 
     def get_packets(self):

+ 13 - 0
code/ID2TLib/Statistics.py

@@ -190,6 +190,19 @@ class Statistics:
         capture_duration = float(self.get_capture_duration())
         return int(float(packets_sent) / capture_duration)
 
+    def get_pps_received(self, ip_address: str):
+        """
+        Calculate the packets per second received for a given IP address.
+
+        :param ip_address: The IP address used for the calculation
+        :return: The number of packets per second received
+        """
+        packets_received = self.stats_db.process_db_query("SELECT pktsReceived FROM ip_statistics WHERE ipAddress=?",
+                                                          False,
+                                                          (ip_address,))
+        capture_duration = float(self.get_capture_duration())
+        return int(float(packets_received) / capture_duration)
+
     def get_packet_count(self):
         """
         :return: The number of packets in the loaded PCAP file