Ejemplo n.º 1
0
def main():
    wav_timing = dict()
    for path in get_files(ARGS.timing, ext='_wav.csv'):
        wav_timing.update(get_wav_timing(path))

    of = open(ARGS.output, 'w')
    writer = csv.writer(of)
    writer.writerow(['device', 'command', 'rtt', 'hop'])
    for path in get_files(ARGS.input, ext='.csv'):
        device_command = '.'.join((path.split('/')[-1]).split('.')[:-1])
        device, command = device_command.split('-')
        commandStart = wav_timing[device_command]['commandStart']
        commandEnd = wav_timing[device_command]['commandEnd']
        serviceStart = wav_timing[device_command]['serviceStart']
        try:
            voice_server = get_voice(path, float(commandStart),
                                     float(commandEnd), float(serviceStart))
        except:
            print('Error', path)

        try:
            head_path = '.'.join(path.split('.')[:-1]) + '.head'
            rtt, hop = get_rtt_hop(head_path, voice_server)
            writer.writerow([device, command, rtt, hop])
        except:
            print('Error', path)

    of.close()
Ejemplo n.º 2
0
def main():
    # create output directory
    os.makedirs(ARGS.wav_output, exist_ok=True)
    # check create or append
    mode = 'w'
    # get manually analyzed result
    manual_timing = get_manual_result(ARGS.manual)
    # go something...
    with open(ARGS.output, mode) as f:
        # prepare output file
        writer = csv.DictWriter(f, fieldnames=FIELDNAMES)
        if f.mode == 'w':
            writer.writeheader()
        # read analysis target file
        for path in get_files(ARGS.input, ext='.wav'):
            print('Start: {0}'.format(path))  # for DEBUG
            try:
                timing = get_timing(path, manual_timing)
            except IndexError:
                print('Too quite: {0}'.format(path))
                continue
            filename = path.split('/')[-1]
            timing['device'] = filename.split('-')[0]
            timing['command'] = (filename.split('-')[1]).split('.')[0]
            writer.writerow(timing)

            # The another thing: for drawing waterfall chart
            histogram = get_histogram(path, float(timing['serviceEnd']))
            filename = path.split('/')[-1]
            histname = '{0}.csv'.format('.'.join(filename.split('.')[:-1]))
            hist_path = os.path.join(ARGS.wav_output, histname)
            np.savetxt(hist_path, histogram, delimiter=',')

            print('End: {0}'.format(path))
Ejemplo n.º 3
0
def main():
    wav_timing = dict()
    for path in get_files(ARGS.timing, ext='_wav.csv'):
        wav_timing.update(get_wav_timing(path))

    of = open(ARGS.output, 'w')
    writer = csv.writer(of)
    writer.writerow(['device', 'command', 'conns'])
    for path in get_files(ARGS.input, ext='.csv'):
        device_command = '.'.join((path.split('/')[-1]).split('.')[:-1])
        device, command = device_command.split('-')
        callStart = wav_timing[device_command]['callStart']
        serviceEnd = wav_timing[device_command]['serviceEnd']
        conns = get_conns(path, float(callStart), float(serviceEnd))

        writer.writerow([device, command, conns])
    of.close()
Ejemplo n.º 4
0
def main():
    for path in get_files(ARGS.input, ext='.csv'):
        with open(path, 'r') as f:
            reader = csv.DictReader(f)
            for row in reader:
                print('{0},{1},{2},{3}'.format(
                    row['device'], row['command'],
                    float(row['actionStart']) - float(row['commandStart']),
                    float(row['actionStart']) - float(row['commandEnd'])))
Ejemplo n.º 5
0
def main():
    # make output dir
    make_dirs(ARGS.output)

    # analyze file by file
    for path in get_files(ARGS.input, ext='.pcap'):
        print('Start: {0}'.format(path))
        output_path = get_output_path(path)
        export_pcap_timing(path, output_path)
        print('Done: {0}'.format(output_path))
Ejemplo n.º 6
0
def main():
    wav_timing = dict()
    for path in get_files(ARGS.timing, ext='_wav.csv'):
        wav_timing.update(get_wav_timing(path))

    of = open(ARGS.output, 'w')
    writer = csv.writer(of)
    writer.writerow(['device', 'command', 'stoppage', 't1', 't2'])
    for path in get_files(ARGS.input, ext='.csv'):
        device_command = '.'.join((path.split('/')[-1]).split('.')[:-1])
        device, command = device_command.split('-')
        commandEnd = wav_timing[device_command]['commandEnd']
        serviceStart = wav_timing[device_command]['serviceStart']
        #        try:
        stoppage = get_stoppage(path, float(commandEnd), float(serviceStart))
        #        except:
        #            print('Error', path)

        writer.writerow(
            [device, command, stoppage[0], stoppage[1], stoppage[2]])
    of.close()
Ejemplo n.º 7
0
def main():
    # create output directory
    os.makedirs(ARGS.output, exist_ok=True)

    wav_data = get_wav_data(ARGS.wav_input)
    for path in get_files(ARGS.pcap_input, ext='.csv'):
        print('Start: {0}'.format(path))
        filename = path.split('/')[-1]
        output_path = os.path.join(ARGS.output, filename)
        with open(output_path, 'w') as of:
            writer = csv.DictWriter(of, fieldnames=FIELDNAMES)
            writer.writeheader()
            key = filename.split('.')[0]
            try:
                white = get_min(wav_data[key])
                data = {
                    'key': key,
                    'callStart': wav_data[key]['callStart'],
                    'callEnd': wav_data[key]['callEnd'],
                    'commandStart': wav_data[key]['commandStart'],
                    'commandEnd': wav_data[key]['commandEnd'],
                    'actionStart': wav_data[key]['actionStart'],
                    'actionEnd': wav_data[key]['actionEnd'],
                    'domainLookupStart': 0,
                    'domainLookupEnd': 0,
                    'connectStart': 0,
                    'connectEnd': 0,
                    'secureConnectionStart': 0,
                    'requestStart': 0,
                    'responseStart': 0,
                    'responseEnd': 0,
                    'white': -white
                }
            except KeyError:
                print('Something not found', key)
                continue
            writer.writerow(data)
            with open(path, 'r') as rf:
                reader = csv.DictReader(rf)
                for row in reader:
                    row.update({
                        'callStart': 0,
                        'callEnd': 0,
                        'commandStart': 0,
                        'commandEnd': 0,
                        'actionStart': 0,
                        'actionEnd': 0
                    })
                    white = get_min(row)
                    row['white'] = white
                    writer.writerow(row)
        print('Done: {0}'.format(path))
Ejemplo n.º 8
0
def main(_):
    pprint('Start tcptrace viewer')

    # prepare output file
    if os.path.exists(FLAGS.output):
        of = open(FLAGS.output, 'a')
    else:
        of = open(FLAGS.output, 'w')
    writer = csv.writer(of)
    if of.mode == 'w':
        writer.writerow([
            'device', 'command', 'host1', 'host2', 'comp_conn',
            'total_packets', 'bytes_sent', 'data_sent', 'avg_win_adv'
        ])

    # Loop pcap files
    for path in get_files(FLAGS.input, ext='.pcap'):
        pprint('Processing pcap file: {0}'.format(path))
        # get device and command
        device_command = path.split('/')[-1]
        device_command = device_command.split('.')[0]
        device, command = device_command.split('-')
        # get tcptrace result using subprocess
        result_line = get_tcptrace(path)
        # remove the header, first five lines
        result_line = '\n'.join(result_line.split('\n')[8:])
        # get connections
        conns = result_line.split('================================')
        # print information: export csv
        for conn in conns:
            host1, host2 = get_hosts(conn)
            if host1 is None:
                continue
            comp_conn = get_complete_conn(conn)
            total_packets = get_attributes(conn, 'total packets')
            bytes_sent = get_attributes(conn, 'unique bytes sent')
            data_sent = get_attributes(conn, 'data bytes sent')
            avg_win_adv = get_attributes(conn, 'avg win adv')
            writer.writerow([
                device, command, host1, host2, comp_conn, total_packets,
                bytes_sent, data_sent, avg_win_adv
            ])

    pprint('End tcptrace viewer')
    of.close()
Ejemplo n.º 9
0
def main():
    # make output dir
    make_dirs(ARGS.output)

    wav_data = get_wav_data(ARGS.timing)
    # analyze file by file
    for path in get_files(ARGS.input, ext='.pcap'):
        print('Start: {0}'.format(path))
        device_command = (path.split('/')[-1]).split('.')[0]
        output_path = get_output_path(path)
        try:
            export_pcap_updown(path, output_path,
                               float(wav_data[device_command]['serviceEnd']))
        except KeyError:
            print('Invalid wav csv: {0}'.format(device_command))
            break
            continue
        except ValueError:
            print('Invalid pcap: {0}'.format(path))
            break
            continue
        print('Done: {0}'.format(output_path))
def main():
    # create output directory
    os.makedirs(ARGS.output, exist_ok=True)

    wav_data = get_wav_data(ARGS.timing)
    for path in get_files(ARGS.pcap_input, ext='.csv'):
        # Data prepare
        pcap_path = path
        hist_path = os.path.join(ARGS.wav_input, path.split('/')[-1])
        if not os.path.exists(hist_path):
            print('Hist file not exists: {0}'.format(hist_path))
            continue
        device_command = (path.split('/')[-1]).split('.')[0]
        print('Start: {0}'.format(device_command))
        database = dict()
        with open(pcap_path, 'r') as f:
            reader = csv.DictReader(f)
            for row in reader:
                ttime = float(row['time'])
                while ttime in database.keys():
                    ttime = ttime + 1e-9
                if row['up'] != '-1':
                    point = int(row['up']) + (int(row['updata']) / 1460 * 0.45)
                    flag = 'up'
                elif row['down'] != '-1':
                    point = int(
                        row['down']) - (int(row['downdata']) / 1460 * 0.45)
                    flag = 'down'
                elif row['syn'] != '-1':
                    point = int(row['syn'])
                    flag = 'syn'
                elif row['fin'] != '-1':
                    point = int(row['fin'])
                    flag = 'fin'
                elif row['ssl'] != '-1':
                    point = int(row['ssl'])
                    flag = 'ssl'
                elif row['dns'] != '-1':
                    point = int(row['dns'])
                    flag = 'dns'

                data = {'time': ttime, 'point': point, 'flag': flag}
                database[ttime] = data
        with open(hist_path, 'r') as f:
            reader = csv.reader(f)
            ttime = float(0)
            for row in reader:
                while ttime in database.keys():
                    ttime = ttime + 1e-9
                point = float(row[0]) * 0.45
                data = {'time': ttime, 'point': point, 'flag': 'wav'}
                database[ttime] = data
                ttime = ttime + 0.001
        # Data sorting
        export = list()
        keys = list(database.keys())
        keys.sort()
        for key in keys:
            export.append(database[key])
        # Data export
        filename = path.split('/')[-1]
        output_path = os.path.join(ARGS.output, filename)
        with open(output_path, 'w') as of:
            writer = csv.DictWriter(of, fieldnames=FIELDNAMES)
            writer.writeheader()
            writer.writerows(export)

        # Head file
        head_src = '.'.join(path.split('.')[:-1]) + '.head'
        head_dst = os.path.join(ARGS.output, head_src.split('/')[-1])
        shutil.copy2(head_src, head_dst)

        # line file
        filename = '.'.join((path.split('/')[-1]).split('.')[:-1]) + '.line'
        line_path = os.path.join(ARGS.output, filename)
        with open(line_path, 'w') as lf:
            writer = csv.writer(lf)
            for timing in [
                    'callStart', 'callEnd', 'commandStart', 'commandEnd',
                    'serviceStart', 'serviceEnd'
            ]:
                writer.writerow([wav_data[device_command][timing]])
        print('Done: {0}'.format(path))
Ejemplo n.º 11
0
def main():
    for path in get_files(ARGS.input, ext='.mp4'):
        mp4_path = path
        pcap_path = path[:-3] + 'pcap'
        print(mp4_path, pcap_path, sync_a_b(mp4_path, pcap_path), sep=',')