[statistiques] Nettoyage pour l'IPv6
darcs-hash:20110507220345-ffbb2-7f25f6dce54708cb58e0f50c899446d54d6d6f5d.gz
This commit is contained in:
parent
3cb768bfaf
commit
9e6237a7b0
1 changed files with 9 additions and 32 deletions
|
@ -30,29 +30,6 @@ from ldap_crans import AssociationCrans, crans_ldap
|
||||||
|
|
||||||
CL = 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):
|
def ipv4or6(addr):
|
||||||
if ':' in addr:
|
if ':' in addr:
|
||||||
return "IPv6"
|
return "IPv6"
|
||||||
|
@ -90,9 +67,9 @@ WHERE
|
||||||
GROUP BY ip_crans
|
GROUP BY ip_crans
|
||||||
ORDER BY somme DESC"""
|
ORDER BY somme DESC"""
|
||||||
curseur.execute(requete)
|
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()
|
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'],
|
titre = ['upload', 'download', 'proto', 'machine'],
|
||||||
largeur = [10, 10, 10, 40],
|
largeur = [10, 10, 10, 40],
|
||||||
format = ['o', 'o', 's', 's'],
|
format = ['o', 'o', 's', 's'],
|
||||||
|
@ -114,7 +91,7 @@ WHERE
|
||||||
GROUP BY ip_crans
|
GROUP BY ip_crans
|
||||||
ORDER BY somme DESC"""
|
ORDER BY somme DESC"""
|
||||||
curseur.execute(requete)
|
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()],
|
for l in curseur.fetchall()],
|
||||||
titre = ['upload', 'download', 'machine'],
|
titre = ['upload', 'download', 'machine'],
|
||||||
largeur = [10, 10, 30],
|
largeur = [10, 10, 30],
|
||||||
|
@ -126,7 +103,7 @@ liste_exemptes = tableau(data = [[l[1], l[2], gethostname(str(l[0]))]
|
||||||
#######################
|
#######################
|
||||||
liste_serveurs = []
|
liste_serveurs = []
|
||||||
for IP in serveurs_ips:
|
for IP in serveurs_ips:
|
||||||
hostname = gethostname(IP)
|
hostname = socket.getfqdn(IP)
|
||||||
requete = """SELECT sum(upload), sum(download)
|
requete = """SELECT sum(upload), sum(download)
|
||||||
FROM upload
|
FROM upload
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -165,7 +142,7 @@ WHERE
|
||||||
GROUP BY ip_ext"""
|
GROUP BY ip_ext"""
|
||||||
curseur.execute(requete)
|
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()],
|
for l in curseur.fetchall()],
|
||||||
titre = ['nombre','ip'],
|
titre = ['nombre','ip'],
|
||||||
largeur = [10, 30],
|
largeur = [10, 30],
|
||||||
|
@ -185,7 +162,7 @@ curseur.execute(requete)
|
||||||
infections = [ x[0] for x in curseur.fetchall() ]
|
infections = [ x[0] for x in curseur.fetchall() ]
|
||||||
liste_virus = []
|
liste_virus = []
|
||||||
for IP in infections:
|
for IP in infections:
|
||||||
hostname = gethostname(IP)
|
hostname = socket.getfqdn(IP)
|
||||||
liste_virus.append(["%s" % (str(hostname))])
|
liste_virus.append(["%s" % (str(hostname))])
|
||||||
|
|
||||||
liste_virus = tableau(liste_virus,
|
liste_virus = tableau(liste_virus,
|
||||||
|
@ -201,7 +178,7 @@ WHERE tous.compteur>'%s' LIMIT 30""" % config.virus.virus
|
||||||
curseur.execute(requete)
|
curseur.execute(requete)
|
||||||
liste_virus2 = []
|
liste_virus2 = []
|
||||||
for IP, compteur in curseur.fetchall():
|
for IP, compteur in curseur.fetchall():
|
||||||
hostname = gethostname(IP)
|
hostname = socket.getfqdn(IP)
|
||||||
liste_virus2.append([hostname, compteur])
|
liste_virus2.append([hostname, compteur])
|
||||||
liste_virus2 = tableau(data = liste_virus2,
|
liste_virus2 = tableau(data = liste_virus2,
|
||||||
titre = ['machine', 'nombre'],
|
titre = ['machine', 'nombre'],
|
||||||
|
@ -219,7 +196,7 @@ WHERE tous.compteur>'%s' LIMIT 30""" % config.virus.flood
|
||||||
curseur.execute(requete)
|
curseur.execute(requete)
|
||||||
liste_virus3 = []
|
liste_virus3 = []
|
||||||
for IP, compteur in curseur.fetchall():
|
for IP, compteur in curseur.fetchall():
|
||||||
hostname = gethostname(IP)
|
hostname = socket.getfqdn(IP)
|
||||||
liste_virus3.append([hostname, compteur])
|
liste_virus3.append([hostname, compteur])
|
||||||
liste_virus3 = tableau(data = liste_virus3,
|
liste_virus3 = tableau(data = liste_virus3,
|
||||||
titre = ['machine', 'nombre'],
|
titre = ['machine', 'nombre'],
|
||||||
|
@ -246,7 +223,7 @@ requete = """SELECT ip_src, nom, compteur, max(date) FROM
|
||||||
curseur.execute(requete)
|
curseur.execute(requete)
|
||||||
liste_p2p = []
|
liste_p2p = []
|
||||||
for IP, protocole, compteur, blackliste in curseur.fetchall():
|
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
|
# Le champ blackliste contient la date du blacklistage si il a eu lieu
|
||||||
if blackliste :
|
if blackliste :
|
||||||
liste_p2p.append(['*%s*' % hostname,
|
liste_p2p.append(['*%s*' % hostname,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue