+ # If the destination is not local, then it's outbound traffic, and hence the eth_src is the MAC of the IoT device.
+ hostname = device_dns_mappings[eth_src].hostname_for_ip_at_time(ip_dst, packet_timestamp)
+ if hostname is None:
+ # Use IP if no hostname mapping
+ hostname = ip_dst
+ G.add_node(hostname)
+ dst_node = hostname
+ G.add_edge(src_node, dst_node)
+
+# # Traffic can be both outbound and inbound.
+# # Determine which one of the two by looking up device MAC in DNS map.
+# iot_device = None
+# if eth_src in device_dns_mappings:
+# iot_device = eth_src
+# elif eth_dst in device_dns_mappings:
+# iot_device = eth_dst
+# else:
+# # print "[ WARNING: DNS mapping not found for device with MAC", eth_src, "OR", eth_dst, "]"
+# # 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(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.
+# outbound_traffic = iot_device == eth_src
+
+
+
+# ''' Graph construction '''
+# # No need to check if the Nodes and/or Edges we add already exist:
+# # NetworkX won't add already existing nodes/edges (except in the case of a MultiGraph or MultiDiGraph (see NetworkX doc)).
+
+# # Add a node for each host.
+# # First add node for IoT 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.
+# # For inbound traffic, the server's IP is the source IP.
+
+# server_ip = ip_dst if outbound_traffic else ip_src
+# hostname = device_dns_mappings[iot_device].hostname_for_ip_at_time(server_ip, packet_timestamp)
+# if hostname is None:
+# # TODO this can occur when two local devices communicate OR if IoT device has hardcoded server IP.
+# # However, we only get here for the DNS that have not performed any DNS lookups
+# # 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(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:
+# G.add_edge(iot_device, hostname)
+# else:
+# G.add_edge(hostname, iot_device)