def callback(hdr, data): #print hdr.getts()[0] global first_pack_timestamp if (first_pack_timestamp == None): #first_pack_timestamp = (hdr.getts()[0] * (10**(-6))) + hdr.getts()[1] #hdr.getts()[1] * (10**(-6)) first_pack_timestamp = hdr.getts()[0] #timestamp = hdr.getts()[1] * (10**(-6)) #timestamp = (hdr.getts()[0] * (10**(-6))) + hdr.getts()[1] timestamp = hdr.getts()[0] delta_time = timestamp - first_pack_timestamp #print "[%i] %f - %f = %f" % (num_packs, timestamp, first_pack_timestamp, delta_time ) global num_packs global num_ips if num_packs <= 10: #print "callback()" packet=decoder.decode(data) l2=packet.child() if isinstance(l2, IP): #print "IP", l3=l2.child() src_ip = l2.get_ip_src() dst_ip = l2.get_ip_dst() if isinstance(l3, TCP): src_port = l3.get_th_sport() dst_port = l3.get_th_dport() else: if isinstance(l3, UDP): #print "UDP" src_port = l2.child().get_uh_sport() dst_port = l2.child().get_uh_dport() else: #print "Breaking!" return #print "Packet from %s (%s) to %s(%s) " % (src_ip, src_port, dst_ip, dst_port) if ((src_port == 3908) and (src_ip == my_ip)): #if ((src_port == 3908) and (src_ip == my_ip) and (dst_port == 3908)): num_packs = num_packs + 1 if not (temp.has_key(src_ip)): tmp_packet = Pacote(src_ip, src_port, dst_ip, dst_port) tmp_packet.inc_dst_calls() #temp[src_ip] = tmp_packet temp[dst_ip] = tmp_packet #num_ips = num_ips + 1 # Increment the number of gotten IPs else: tmp_packet = temp[dst_ip] tmp_packet.inc_dst_calls() # Increment the source's number of destination calls temp[dst_ip] = tmp_packet # Saves the incrementation
def callback(hdr, data): #print "callback()" packet=decoder.decode(data) l2=packet.child() if isinstance(l2, IP): #print "IP", l3=l2.child() src_ip = l2.get_ip_src() dst_ip = l2.get_ip_dst() if isinstance(l3, TCP): dst_port = l3.get_th_sport() src_port = l3.get_th_dport() #print "TCP from %s (%s) to %s(%s) " % (src_ip, src_port, dst_ip, dst_port) if isinstance(l3, UDP): #print "UDP" dst_port = l2.child().get_uh_sport() src_port = l2.child().get_uh_dport() if not (temp.has_key(src_ip)): tmp_packet = Pacote(src_ip, src_port, dst_ip, dst_port) tmp_packet.inc_dst_calls() temp[src_ip] = tmp_packet else: tmp_packet = temp[src_ip] tmp_packet.inc_dst_calls() # Increment the source's number of destination calls temp[src_ip] = tmp_packet # Saves the incrementation if not (temp.has_key(dst_ip)): tmp_packet = Pacote(dst_ip, dst_port, src_ip, src_port) temp[dst_ip] = tmp_packet tmp_packet = temp[dst_ip] tmp_packet.inc_dst_calls() # Increment the destination's number of destination calls # Notice that this number represents different things for the # viewer IP and for all the other sources temp[dst_ip] = tmp_packet