On colle les try-except partout pour le gethostbyname.
darcs-hash:20061108115126-1dcb7-c257cdbae1519eeb2dae15bf83b4a0ecc2f99ecb.gz
This commit is contained in:
parent
8666876c08
commit
71177d4b05
1 changed files with 13 additions and 16 deletions
|
@ -25,6 +25,13 @@ from analyse import stats
|
|||
from affich_tools import tableau
|
||||
from ldap_crans import AssociationCrans
|
||||
|
||||
# Fonction retournant l'hote quand c'est possible
|
||||
def gethostname(s):
|
||||
try:
|
||||
return socket.gethostbyaddr(s)[0]
|
||||
except:
|
||||
return s
|
||||
|
||||
# Liste des IP des serveurs
|
||||
serveurs_ips = (
|
||||
'138.231.136.10', '138.231.136.1', '138.231.136.3', '138.231.136.4',
|
||||
|
@ -39,13 +46,6 @@ pgsql = PgSQL.connect(host='/var/run/postgresql', database='filtrage', user='cra
|
|||
curseur = pgsql.cursor()
|
||||
mail = smtplib.SMTP('localhost')
|
||||
|
||||
# Probablement à mettre ailleurs
|
||||
def gethostname(s):
|
||||
try:
|
||||
return socket.gethostbyaddr(s)[0]
|
||||
except:
|
||||
return s
|
||||
|
||||
###########################
|
||||
# Statistiques d'upload : #
|
||||
###########################
|
||||
|
@ -82,7 +82,7 @@ liste_upload = tableau(data = [ (l[1], l[2], gethostname(str(l[0])))
|
|||
###################
|
||||
requete = "SELECT ip_crans,sum(upload) AS somme , sum(download) FROM upload WHERE ip_crans IN ( SELECT ip_crans from exemptes) and date > timestamp 'now' - interval '1 day' GROUP BY ip_crans ORDER BY somme DESC"
|
||||
curseur.execute(requete)
|
||||
liste_exemptes = tableau(data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0] ] for l in curseur.fetchall() ],
|
||||
liste_exemptes = tableau(data = [ [l[1], l[2], gethostname(str(l[0])) ] for l in curseur.fetchall() ],
|
||||
titre = ['upload', 'download', 'machine'],
|
||||
largeur = [10, 10, 30],
|
||||
format = ['o', 'o', 's'],
|
||||
|
@ -93,7 +93,7 @@ liste_exemptes = tableau(data = [ [l[1], l[2], socket.gethostbyaddr(str(l[0]))[0
|
|||
#######################
|
||||
liste_serveurs = []
|
||||
for IP in serveurs_ips:
|
||||
hostname = socket.gethostbyaddr(IP)[0]
|
||||
hostname = gethostname(IP)
|
||||
requete = """SELECT sum(upload), sum(download)
|
||||
FROM upload
|
||||
WHERE
|
||||
|
@ -127,10 +127,7 @@ curseur.execute(requete)
|
|||
infections = [ x[0] for x in curseur.fetchall() ]
|
||||
liste_virus = []
|
||||
for IP in infections:
|
||||
try:
|
||||
hostname = socket.gethostbyaddr("%s" % IP)[0]
|
||||
except socket.herror:
|
||||
continue
|
||||
hostname = gethostname(IP)
|
||||
liste_virus.append(["%s" % (str(hostname))])
|
||||
|
||||
liste_virus = tableau(liste_virus, titre=['machine'], largeur=[30]).encode('iso-8859-15')
|
||||
|
@ -141,7 +138,7 @@ requete = "SELECT * FROM (SELECT ip_src,count(ip_src) as compteur FROM virus WHE
|
|||
curseur.execute(requete)
|
||||
liste_virus2 = []
|
||||
for IP, compteur in curseur.fetchall():
|
||||
hostname = socket.gethostbyaddr(IP)[0]
|
||||
hostname = gethostname(IP)
|
||||
liste_virus2.append([hostname, compteur])
|
||||
liste_virus2 = tableau(data = liste_virus2,
|
||||
titre = ['machine', 'nombre'],
|
||||
|
@ -155,7 +152,7 @@ requete = "SELECT * FROM (SELECT ip_src,count(ip_src) as compteur FROM flood WHE
|
|||
curseur.execute(requete)
|
||||
liste_virus3 = []
|
||||
for IP, compteur in curseur.fetchall():
|
||||
hostname = socket.gethostbyaddr(IP)[0]
|
||||
hostname = gethostname(IP)
|
||||
liste_virus3.append([hostname, compteur])
|
||||
liste_virus3 = tableau(data = liste_virus3,
|
||||
titre = ['machine', 'nombre'],
|
||||
|
@ -182,7 +179,7 @@ requete = "SELECT ip_src, nom, compteur, max(date) FROM \
|
|||
curseur.execute(requete)
|
||||
liste_p2p = []
|
||||
for IP, protocole, compteur, blackliste in curseur.fetchall():
|
||||
hostname = socket.gethostbyaddr(IP)[0]
|
||||
hostname = gethostname(IP)
|
||||
# Le champ blackliste contient la date du blacklistage si il a eu lieu
|
||||
if blackliste :
|
||||
liste_p2p.append(['*%s*' % hostname,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue