From 9e6237a7b04530be44455a1444f1e7099896f000 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Sun, 8 May 2011 00:03:45 +0200 Subject: [PATCH] [statistiques] Nettoyage pour l'IPv6 darcs-hash:20110507220345-ffbb2-7f25f6dce54708cb58e0f50c899446d54d6d6f5d.gz --- surveillance/statistiques.py | 41 ++++++++---------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/surveillance/statistiques.py b/surveillance/statistiques.py index 8efcd7a9..5b4abd36 100644 --- a/surveillance/statistiques.py +++ b/surveillance/statistiques.py @@ -30,29 +30,6 @@ from ldap_crans import AssociationCrans, crans_ldap CL = crans_ldap() -# Fonction retournant l'hote quand c'est possible -def gethostname(ip): - # Poor man's IPv6 reverse DNS... - if ":" in ip: - # reconstruction de l'EUI48 à partir de l'EUI64... - addr_bits = list(netaddr.IPAddress(ip).bits('')) - addr_bits[0:64] = [] - addr_bits[24:40] = [] - addr_bits[6] = '0' - addr_bits = ''.join(addr_bits) - mac = ':'.join("%02x" % int(addr_bits[8*i:8*i+8], 2) for i in range(6)) - res = CL.search("mac=%s" % mac) - noms = sorted(r.nom() for r in res["machineFixe"] + res["machineWifi"] + res["machineCrans"] if r.nom().endswith('crans.org')) - if noms: - return str(noms[0]) - else: - return ip - else: - try: - return socket.gethostbyaddr(ip)[0] - except: - return ip - def ipv4or6(addr): if ':' in addr: return "IPv6" @@ -90,9 +67,9 @@ WHERE GROUP BY ip_crans ORDER BY somme DESC""" curseur.execute(requete) -liste_upload = tableau(data = [ (l[1], l[2], ipv4or6(str(l[0])), gethostname(str(l[0]))) +liste_upload = tableau(data = [ (l[1], l[2], ipv4or6(str(l[0])), socket.getfqdn(str(l[0]))) for l in curseur.fetchall() - if int(l[1]) > 100*1024*1024 or ':' in l[0]], + if int(l[1]) > 100*1024*1024], titre = ['upload', 'download', 'proto', 'machine'], largeur = [10, 10, 10, 40], format = ['o', 'o', 's', 's'], @@ -114,7 +91,7 @@ WHERE GROUP BY ip_crans ORDER BY somme DESC""" curseur.execute(requete) -liste_exemptes = tableau(data = [[l[1], l[2], gethostname(str(l[0]))] +liste_exemptes = tableau(data = [[l[1], l[2], socket.getfqdn(str(l[0]))] for l in curseur.fetchall()], titre = ['upload', 'download', 'machine'], largeur = [10, 10, 30], @@ -126,7 +103,7 @@ liste_exemptes = tableau(data = [[l[1], l[2], gethostname(str(l[0]))] ####################### liste_serveurs = [] for IP in serveurs_ips: - hostname = gethostname(IP) + hostname = socket.getfqdn(IP) requete = """SELECT sum(upload), sum(download) FROM upload WHERE @@ -165,7 +142,7 @@ WHERE GROUP BY ip_ext""" curseur.execute(requete) -liste_etherunk = tableau(data = [[l[0], gethostname(str(l[1]))] +liste_etherunk = tableau(data = [[l[0], socket.getfqdn(str(l[1]))] for l in curseur.fetchall()], titre = ['nombre','ip'], largeur = [10, 30], @@ -185,7 +162,7 @@ curseur.execute(requete) infections = [ x[0] for x in curseur.fetchall() ] liste_virus = [] for IP in infections: - hostname = gethostname(IP) + hostname = socket.getfqdn(IP) liste_virus.append(["%s" % (str(hostname))]) liste_virus = tableau(liste_virus, @@ -201,7 +178,7 @@ WHERE tous.compteur>'%s' LIMIT 30""" % config.virus.virus curseur.execute(requete) liste_virus2 = [] for IP, compteur in curseur.fetchall(): - hostname = gethostname(IP) + hostname = socket.getfqdn(IP) liste_virus2.append([hostname, compteur]) liste_virus2 = tableau(data = liste_virus2, titre = ['machine', 'nombre'], @@ -219,7 +196,7 @@ WHERE tous.compteur>'%s' LIMIT 30""" % config.virus.flood curseur.execute(requete) liste_virus3 = [] for IP, compteur in curseur.fetchall(): - hostname = gethostname(IP) + hostname = socket.getfqdn(IP) liste_virus3.append([hostname, compteur]) liste_virus3 = tableau(data = liste_virus3, titre = ['machine', 'nombre'], @@ -246,7 +223,7 @@ requete = """SELECT ip_src, nom, compteur, max(date) FROM curseur.execute(requete) liste_p2p = [] for IP, protocole, compteur, blackliste in curseur.fetchall(): - hostname = gethostname(IP) + hostname = socket.getfqdn(IP) # Le champ blackliste contient la date du blacklistage si il a eu lieu if blackliste : liste_p2p.append(['*%s*' % hostname,