INNER CODE UNIT · Python

entropy

A3sal0n/CyberThreatHunting · tools/bro-dns-iforest.py:49

def entropy(s):
    "Calculates the Boltzmann entropy of a string"
    l = float(len(s))
    return -sum(map(lambda a: (a / l) * math.log((a / l), 2), Counter(s).values()))


def select_fields(data):
    output = []
    selected = []
    for i in range(len(data)):
        try:
            row = {}
            if '.local' not in data[i]['query']:
                row['id.resp_p'] = int(data[i]['id.resp_p'])
                row['rtt'] = int(float(data[i]['rtt']) * 1000)
                row['q_length'] = len(data[i]['query'])
                row['q_entropy'] = entropy(data[i]['query'])
                row['qclass'] = int(data[i]['qclass'])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…