Dans affich_tools, tableau_ng remplace dornavant tableau.

darcs-hash:20060326160011-68412-d87c57d6e2edf22dd78fd5c78e07793a19421ff5.gz
This commit is contained in:
glondu 2006-03-26 18:00:11 +02:00
parent 821905a295
commit 7428178ab9
5 changed files with 101 additions and 123 deletions

View file

@ -5,9 +5,9 @@ import socket
import sys, re
from pyPgSQL import PgSQL
sys.path.append('/usr/scripts/gestion/')
from affich_tools import tableau_ng
from affich_tools import tableau
def stats (ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_ext'], upload_mini=0, show_limit=10, begin_time=24, end_time=0):
def stats(ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_ext'], upload_mini=0, show_limit=10, begin_time=24, end_time=0):
"""
Retourne une chaine de caratères formatée avec le tableau de statistiques
d'upload de l'ip fourni
@ -91,16 +91,16 @@ def stats (ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_
# on modifie les ip en noms de machine et les ports en noms
def nom_de_machine (ip) :
try :
try:
return socket.gethostbyaddr(ip)[0]
except :
except:
return ip
port_to_service = {}
for service,port in [ re.split('[ \t]+',x.strip().replace('/tcp','').replace('/udp',''))[:2] for x in open('/etc/services').readlines() if x[0] not in ['\n','#'] ] :
port_to_service[port]=service
for champ in select :
for champ in select:
if champ == 'ip_ext':
col = select.index(champ)
results = [ x[:col] + [nom_de_machine(x[col])] + x[col+1:] for x in results ]
@ -113,7 +113,7 @@ def stats (ip_crans=[], ip_ext=[], show=['ip_crans','ip_ext','port_crans','port_
col = select.index(champ)
results = [ x[:col] + [port_to_service.get(x[col],x[col])] + x[col+1:] for x in results ]
return tableau_ng(results, titre=titre, largeur=largeur, alignement=alignement, format=format)
return tableau(results, titre=titre, largeur=largeur, alignement=alignement, format=format)
if __name__ == '__main__' :
@ -261,5 +261,5 @@ Exemples :
# affichage du résultat
#######################
#print stats(ip_crans, group, upload_mini, limit, heures)
print stats (ip_crans, ip_ext, show, upload_mini, limit, begin_time, end_time)
print stats(ip_crans, ip_ext, show, upload_mini, limit, begin_time, end_time)