<commit_before># -*- coding: utf-8 -*-

import dpkt, dpkt.dns
import sys
import socket
import pcap
import subprocess

type_table = {}  # This is a lookup table for DNS query types

dns_whitelist = ['192.168.1.1' , '8.8.8.8']


def initialize_tables():
    global type_table


    # From http://www.networksorcery.com/enp/protocol/dns.htm
    type_table = {1: "A",  # IP v4 address, RFC 1035
                  2: "NS",  # Authoritative name server, RFC 1035
                  5: "CNAME",  # Canonical name for an alias, RFC 1035
                  6: "SOA",  # Marks the start of a zone of authority, RFC 1035
                  12: "PTR",  # Domain name pointer, RFC 1035
                  13: "HINFO",  # Host information, RFC 1035
                  15: "MX",  # Mail exchange, RFC 1035
                  28: "AAAA",  # IP v6 address, RFC 3596
    }



def processa(src, dst, sport, dport, data,vett_siti_err,vett_siti_ok):
    # Uncomment if you want to see all UDP packets
    # print "from ", socket.inet_ntoa(src),":",sport, " to ", socket.inet_ntoa(dst),":",dport
    #if dport == 53 :
    #    # UDP/53 is a DNS query
    #    dns = dpkt.dns.DNS(data)
    #    if dns.opcode != dpkt.dns.DNS_QUERY :
    #        print "A DNS packet was sent to the nameserver, but the opcode was %d instead of DNS_QUERY (this is a software error)" % dns.opcode
    #    if dns.qr != dpkt.dns.DNS_Q :
    #        print "A DNS packet was sent to the name server, but dns.qr is not 0 and should be. It is %d" % dns.qr
    #    print "query for ", dns.qd[0].name, "ID is ", dns.id, "dns.qr is ", dns.qr, "query type is ", dns.qd[0].type, type_table[dns.qd[0].type]
    #    print "dns.qd is ", dns.qd<commit_msg>creata la funzione per il loading automatico dei dns in whitelist(va fatto che legga un file di testo magari)<commit_after># -*- coding: utf-8 -*-

import dpkt, dpkt.dns
import sys
import socket
import pcap
import subprocess

type_table = {}  # This is a lookup table for DNS query types

dns_whitelist = []


def loadDns():
    #funzione per il caricamento dinamico dei dns(va poi implementato)
    global dns_whitelist
    dns_whitelist = ['192.168.1.1' , '8.8.8.8']

def initialize_tables():
    global type_table


    # From http://www.networksorcery.com/enp/protocol/dns.htm
    type_table = {1: "A",  # IP v4 address, RFC 1035
                  2: "NS",  # Authoritative name server, RFC 1035
                  5: "CNAME",  # Canonical name for an alias, RFC 1035
                  6: "SOA",  # Marks the start of a zone of authority, RFC 1035
                  12: "PTR",  # Domain name pointer, RFC 1035
                  13: "HINFO",  # Host information, RFC 1035
                  15: "MX",  # Mail exchange, RFC 1035
                  28: "AAAA",  # IP v6 address, RFC 3596
    }



def processa(src, dst, sport, dport, data,vett_siti_err,vett_siti_ok):
    if len(dns_whitelist) == 0:
        loadDns()
    # Uncomment if you want to see all UDP packets
    # print "from ", socket.inet_ntoa(src),":",sport, " to ", socket.inet_ntoa(dst),":",dport
    #if dport == 53 :
    #    # UDP/53 is a DNS query
    #    dns = dpkt.dns.DNS(data)
    #    if dns.opcode != dpkt.dns.DNS_QUERY :
    #        print "A DNS packet was sent to the nameserver, but the opcode was %d instead of DNS_QUERY (this is a software error)" % dns.opcode
    #    if dns.qr != dpkt.dns.DNS_Q :
    #        print "A DNS packet was sent to the name server, but dns.qr is not 0 and should be. It is %d" % dns.qr
    #    print "query for ", dns.qd[0].name, "ID is ", dns.id, "dns.qr is ", dns.qr, "query type is ", dns.qd[0].type, type_table[dns.qd[0].type]
    #    print "dns.qd is ", dns.qd
{'fraction_non_alphanumeric': 0.1219047619047619, 'fraction_numerical': 0.036734693877551024, 'mean_word_length': 2.308730873087309, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '166446', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1314, 'n_words': 425}