Setting device name as attribute (on Gephi we can choose to display/not display it)
authorrtrimana <rtrimana@uci.edu>
Tue, 7 Nov 2017 16:43:29 +0000 (08:43 -0800)
committerrtrimana <rtrimana@uci.edu>
Tue, 7 Nov 2017 16:43:29 +0000 (08:43 -0800)
base_gefx_generator.py

index f7b874973b6d9a1897230bef14844f3835d78ea5..ca3aba70c4006ef6a9776f8b06fb3b5eb86cec3c 100644 (file)
@@ -64,8 +64,6 @@ def parse_json(file_path):
             # Traffic can be both outbound and inbound.
             # Determine which one of the two by looking up device MAC in DNS map.
             iot_device = None
             # Traffic can be both outbound and inbound.
             # Determine which one of the two by looking up device MAC in DNS map.
             iot_device = None
-            src = eth_src + "-" + devlist[eth_src]
-            dst = eth_dst + "-" + devlist[eth_dst]
             if eth_src in device_dns_mappings:
                 iot_device = eth_src
             elif eth_dst in device_dns_mappings:
             if eth_src in device_dns_mappings:
                 iot_device = eth_src
             elif eth_dst in device_dns_mappings:
@@ -75,9 +73,9 @@ def parse_json(file_path):
                 # This must be local communication between two IoT devices OR an IoT device talking to a hardcoded IP.
                 # For now let's assume local communication.
                 # Add a node for each device and an edge between them.
                 # This must be local communication between two IoT devices OR an IoT device talking to a hardcoded IP.
                 # For now let's assume local communication.
                 # Add a node for each device and an edge between them.
-                G.add_node(src)
-                G.add_node(dst)
-                G.add_edge(src, dst)
+                G.add_node(eth_src, Name=devlist[eth_src])
+                G.add_node(eth_dst, Name=devlist[eth_src])
+                G.add_edge(eth_src, eth_dst)
                 # TODO add regex check on src+dst IP to figure out if hardcoded server IP (e.g. check if one of the two are NOT a 192.168.x.y IP)
                 continue
             # It is outbound traffic if iot_device matches src, otherwise it must be inbound traffic.
                 # TODO add regex check on src+dst IP to figure out if hardcoded server IP (e.g. check if one of the two are NOT a 192.168.x.y IP)
                 continue
             # It is outbound traffic if iot_device matches src, otherwise it must be inbound traffic.
@@ -89,8 +87,7 @@ def parse_json(file_path):
             
             # Add a node for each host.
             # First add node for IoT device.
             
             # Add a node for each host.
             # First add node for IoT device.
-            device = iot_device + "-" + devlist[iot_device]
-            G.add_node(device)
+            G.add_node(iot_device, Name=devlist[eth_src])
             # Then add node for the server.
             # For this we need to distinguish between outbound and inbound traffic so that we look up the proper IP in our DNS map.
             # For outbound traffic, the server's IP is the destination IP.
             # Then add node for the server.
             # For this we need to distinguish between outbound and inbound traffic so that we look up the proper IP in our DNS map.
             # For outbound traffic, the server's IP is the destination IP.
@@ -103,16 +100,16 @@ def parse_json(file_path):
                 # We should use a regex check early in the loop to see if it is two local devices communicating.
                 # This way we would not have to consider these corner cases later on.
 #                print "[ WARNING: no ip-hostname mapping found for ip", server_ip, " -- adding eth.src->eth.dst edge, but note that this may be incorrect if IoT device has hardcoded server IP ]"
                 # We should use a regex check early in the loop to see if it is two local devices communicating.
                 # This way we would not have to consider these corner cases later on.
 #                print "[ WARNING: no ip-hostname mapping found for ip", server_ip, " -- adding eth.src->eth.dst edge, but note that this may be incorrect if IoT device has hardcoded server IP ]"
-                G.add_node(src)
-                G.add_node(dst)
-                G.add_edge(src, dst)
+                G.add_node(eth_src, Name=devlist[eth_src])
+                G.add_node(eth_dst, Name=devlist[eth_src])
+                G.add_edge(eth_src, eth_dst)
                 continue
             G.add_node(hostname)
             # Connect the two nodes we just added.
             if outbound_traffic:
                 continue
             G.add_node(hostname)
             # Connect the two nodes we just added.
             if outbound_traffic:
-                G.add_edge(device, hostname)
+                G.add_edge(iot_device, hostname)
             else:
             else:
-                G.add_edge(hostname, device)
+                G.add_edge(hostname, iot_device)
     return G
 
 # ------------------------------------------------------
     return G
 
 # ------------------------------------------------------