示例#1
0
文件: test.py 项目: CarlEkerot/Exjobb
#! /usr/bin/env python

import pcap_glue
import protocol_analyser
import pcap_reassembler

packets = pcap_reassembler.load_pcap('../cap/dns-30628-packets.pcap', strict=True)
nums = [p.number for p in packets]
truth = []
with open('../cap/dns.csv.clean') as f:
    for line in f:
        (no, type_) = line.split(',')
        if int(no) in nums:
            truth.append(type_[:-1])

msgs = pcap_glue.build_messages('../cap/dns-30628-packets.pcap')
an = protocol_analyser.ProtocolAnalyser(msgs[:20000], 100, truth)
an.cluster(200, max_num_types=10)
#an.state_inference('dns-state_diagram.png', 5)
#an.classify_fields()

示例#2
0
from itertools import product
from pickle import dump
from pcap_glue import build_messages
from protocol_analyser import ProtocolAnalyser

# Suppress stdout
#sys.stdout = open(os.devnull, 'w')

sizes = [1000]
min_samples = [10]

input_file = '/media/data/cap/dns-30628-packets.pcap'
output_path = '/media/data/dns/'

msgs = build_messages(input_file)

def benchmark(size, min_samples):
    an = ProtocolAnalyser(msgs[:size], 200)
    an.cluster(min_samples, max_num_types=10)
    an.classify_fields()

    data = {
        'size':         size,
        'min_samples':  min_samples,
        'labels':       an.labels,
        'global_est':   an.global_est,
        'cluster_est':  an.cluster_est,
    }

    if not os.path.exists(output_path):