فهرست منبع

Finally got a bug-riddled version of merged id2t working on my machine

Denis Waßmann 6 سال پیش
والد
کامیت
dad8c1678a
3فایلهای تغییر یافته به همراه49 افزوده شده و 2 حذف شده
  1. 1 1
      code/Attack/MembersMgmtCommAttack.py
  2. 47 0
      code/Core/Statistics.py
  3. 1 1
      code/Core/StatsDatabase.py

+ 1 - 1
code/Attack/MembersMgmtCommAttack.py

@@ -253,7 +253,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
 
         # write the mapping to a file
         dest_without_ext = os.path.splitext(ID2TLib.Utility.PCAP_DEST_PATH)[0]
-        msg_packet_mapping.write_to(dest_without_ext + "_mapping.xml")
+        msg_packet_mapping.write_to_file(dest_without_ext + "_mapping.xml")
 
         # Store timestamp of last packet
         self.attack_end_utime = last_packet.time

+ 47 - 0
code/Core/Statistics.py

@@ -7,6 +7,7 @@ from operator import itemgetter
 # TODO: double check this import
 # does it complain because libpcapreader is not a .py?
 import ID2TLib.libpcapreader as pr
+from ID2TLib.IPv4 import IPAddress
 import matplotlib
 
 import Core.StatsDatabase as statsDB
@@ -605,6 +606,52 @@ class Statistics:
             sql_return.remove(result[i])
         return result
 
+    def get_avg_delay_local_ext(self):
+        """
+        Calculates the average delay of a packet for external and local communication, based on the tcp handshakes
+        :return: tuple consisting of avg delay for local and external communication, (local, external)
+        """
+
+        conv_delays = self.stats_db.process_user_defined_query("SELECT ipAddressA, ipAddressB, avgDelay FROM conv_statistics")
+        if(conv_delays):
+            external_conv = []
+            local_conv = []
+
+            for conv in conv_delays:
+                IPA = IPAddress.parse(conv[0])
+                IPB = IPAddress.parse(conv[1])
+
+                #split into local and external conversations
+                if(not IPA.is_private() or not IPB.is_private()):
+                    external_conv.append(conv)
+                else:
+                    local_conv.append(conv)
+
+            # calculate avg local and external delay by summing up the respective delays and dividing them by the number of conversations
+            avg_delay_external = 0.0
+            avg_delay_local = 0.0
+
+            if(local_conv):
+                for conv in local_conv:
+                    avg_delay_local += conv[2]
+                avg_delay_local = (avg_delay_local/len(local_conv)) * 0.001 #ms
+            else:
+                # no local conversations in statistics found
+                avg_delay_local = 0.06
+
+            if(external_conv):
+                for conv in external_conv:
+                    avg_delay_external += conv[2]
+                avg_delay_external = (avg_delay_external/len(external_conv)) * 0.001 #ms
+            else:
+                # no external conversations in statistics found
+                avg_delay_external = 0.15
+        else:
+            #if no statistics were found, use these numbers
+            avg_delay_external = 0.15
+            avg_delay_local = 0.06
+        return avg_delay_local, avg_delay_external
+
     def get_statistics_database(self):
         """
         :return: A reference to the statistics database object

+ 1 - 1
code/Core/StatsDatabase.py

@@ -289,7 +289,7 @@ class StatsDatabase:
             if query_string[-1] != ";":
                 query_string += ";"
             query_list = self.query_parser.parse_query(query_string)
-            print(str(query_list))
+            #print(str(query_list))
             result = self._execute_query_list(query_list)
         else:
             sys.stderr.write(