<commit_before>#!/usr/bin/python

from __future__ import print_function

import sys
import os
import logging
import argparse
import traceback
from circuits import handler,Debugger
from circuits.net.sockets import UDPServer
import dnslib as dl
from collections import defaultdict
from datetime import datetime
import mysql.connector

def parseQueryString(qnm):
    tokens = qnm.split('.')
    res = defaultdict(bool)
    for token in tokens:
        t = token.split('-', 1)
        if len(t) == 2:
            res[t[0]] = t[1]
        else:
            res[t[0]] = True
    return res
    
add_query_db = ("INSERT INTO queries "
               "(exp_id, src_ip, src_port, query, trans_id, ip_id) "
               "VALUES (%s, %s, %s, %s, %s, %s)")

class AServer(UDPServer):
    @handler("read")
    def on_read(self, addr, data):
        request = dl.DNSRecord.parse(data)
        qid = request.header.id
        qname = request.q.qname
        qnm = str(qname).lower()
        qclass = dl.CLASS[request.q.qclass]
        qtype = dl.QTYPE[request.q.qtype]
        
        logging.info("Request from (%s) for (%s %s %s)", addr, qnm, qclass, qtype)

        reply = dl.DNSRecord(dl.DNSHeader(id=qid, qr=1, aa=1, ra=1), q=request.q)        
        <commit_msg>small tweak to logging<commit_after>#!/usr/bin/python

from __future__ import print_function

import sys
import os
import logging
import argparse
import traceback
from circuits import handler,Debugger
from circuits.net.sockets import UDPServer
import dnslib as dl
from collections import defaultdict
from datetime import datetime
import mysql.connector

def parseQueryString(qnm):
    tokens = qnm.split('.')
    res = defaultdict(bool)
    for token in tokens:
        t = token.split('-', 1)
        if len(t) == 2:
            res[t[0]] = t[1]
        else:
            res[t[0]] = True
    return res
    
add_query_db = ("INSERT INTO queries "
               "(exp_id, src_ip, src_port, query, trans_id, ip_id) "
               "VALUES (%s, %s, %s, %s, %s, %s)")

class AServer(UDPServer):
    @handler("read")
    def on_read(self, addr, data):
        request = dl.DNSRecord.parse(data)
        qid = request.header.id
        qname = request.q.qname
        qnm = str(qname).lower()
        qclass = dl.CLASS[request.q.qclass]
        qtype = dl.QTYPE[request.q.qtype]
        
        logging.info("Request id:%s from (%s) for (%s %s %s)", qid, addr, str(qname), qclass, qtype)

        reply = dl.DNSRecord(dl.DNSHeader(id=qid, qr=1, aa=1, ra=1), q=request.q)        
        
{'fraction_non_alphanumeric': 0.12534381139489195, 'fraction_numerical': 0.006286836935166994, 'mean_word_length': 2.536111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2925640', 'n_tokens_mistral': 877, 'n_tokens_neox': 863, 'n_words': 231}