def on_packet(self, pktlen, data, timestamp):
     if not data:
         return
 
     self._last_seen_ts = timestamp
     if self._interval_start == -1:
         self._interval_start = timestamp
 
     if data[12:14] == '\x08\x00':
         decoded_packet = putil.decode_ip_packet(data[14:])
     
         # check if both source and destination address are in the same domain
         sa_dict = self._gi.record_by_addr(decoded_packet['source_address'])
         da_dict = self._gi.record_by_addr(decoded_packet['destination_address'])
         
         if sa_dict is not None and da_dict is not None and sa_dict.has_key('city') and da_dict.has_key('city'):
             if sa_dict['city'] == da_dict['city']:
                 # we count this as intradomain traffic
                 self._intra_packets_size += decoded_packet['total_len']
             else:
                 # we count this as interdomain traffic
                 self._inter_packets_size += decoded_packet['total_len']
         
                 print "ts: %d\tsource: %s\t\tdestination: %s" % (timestamp,
                                                                  decoded_packet['source_address'],
                                                                  decoded_packet['destination_address'])
 
     if (timestamp - self._interval_start) >= self._interval:
         self.write_to_file(timestamp)
Beispiel #2
0
    def on_packet(self, pktlen, data, timestamp):
        if not data:
            return

        self._last_seen_ts = timestamp
        if self._interval_start == -1:
            self._interval_start = timestamp

        if data[12:14] == '\x08\x00':
            decoded_packet = putil.decode_ip_packet(data[14:])

            # check if both source and destination address are in the same domain
            sa_dict = self._gi.record_by_addr(decoded_packet['source_address'])
            da_dict = self._gi.record_by_addr(
                decoded_packet['destination_address'])

            if sa_dict is not None and da_dict is not None and sa_dict.has_key(
                    'city') and da_dict.has_key('city'):
                if sa_dict['city'] == da_dict['city']:
                    # we count this as intradomain traffic
                    self._intra_packets_size += decoded_packet['total_len']
                else:
                    # we count this as interdomain traffic
                    self._inter_packets_size += decoded_packet['total_len']

                    print "ts: %d\tsource: %s\t\tdestination: %s" % (
                        timestamp, decoded_packet['source_address'],
                        decoded_packet['destination_address'])

        if (timestamp - self._interval_start) >= self._interval:
            self.write_to_file(timestamp)
Beispiel #3
0
    def on_packet(self, pktlen, data, timestamp):
        if not data:
            return

        decoded_packet = putil.decode_ip_packet(data[14:])
        outstr = "%d\t%s\t%s\t%d" % (
            timestamp, decoded_packet['source_address'],
            decoded_packet['destination_address'], decoded_packet['total_len'])
        print outstr
        self._out.write(outstr)
        self._out.write('\n')
 def on_packet(self, pktlen, data, timestamp):
     if not data:
         return
     
     decoded_packet = putil.decode_ip_packet(data[14:])
     outstr = "%d\t%s\t%s\t%d" % (timestamp,
                                  decoded_packet['source_address'],
                                  decoded_packet['destination_address'],
                                  decoded_packet['total_len'])
     print outstr
     self._out.write(outstr)
     self._out.write('\n')
Beispiel #5
0
def on_packet(pktlen, data, timestamp):
    global options
    global total_packets_recv
    global total_packets_size

    if not data:
        return

    if data[12:14] == '\x08\x00':
        decoded_packet = putil.decode_ip_packet(data[14:])
        # update global statistics
        total_packets_recv += 1
        total_packets_size += decoded_packet['total_len']

        print_decoded_packet(decoded_packet, timestamp, options.logfile
                             is not None)
def on_packet(pktlen, data, timestamp):
    global options
    global total_packets_recv
    global total_packets_size
    
    if not data:
        return
    
    if data[12:14] == '\x08\x00':
        decoded_packet = putil.decode_ip_packet(data[14:])
        # update global statistics
        total_packets_recv += 1
        total_packets_size += decoded_packet['total_len']        
        
        print_decoded_packet(decoded_packet, 
                             timestamp, 
                             options.logfile is not None)