nettoyage + threading plus propre

darcs-hash:20061007005209-f6463-72a15b48ee8b83826945ff33b154e89122995e31.gz
This commit is contained in:
cohen 2006-10-07 02:52:09 +02:00
parent dfeabde3b1
commit 78b289e130

View file

@ -16,11 +16,11 @@ def format_mac(unformated_mac):
# classe d'interrogation des switchs # classe d'interrogation des switchs
class interroge_switch (threading.Thread) : class interroge_switch (threading.Thread) :
def __init__ (self, tableau, switch, mac = None) : def __init__ (self, switch, mac = None) :
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.tableau=tableau
self.switch = switch self.switch = switch
self.mac = mac self.mac = mac
self.reponse=None
self.start() self.start()
def run (self) : def run (self) :
@ -30,8 +30,8 @@ class interroge_switch (threading.Thread) :
while (prise==None) & (iteration > 0): while (prise==None) & (iteration > 0):
prise = sw.where_is_mac(self.mac) prise = sw.where_is_mac(self.mac)
iteration = iteration-1 iteration = iteration-1
if prise != None : if (prise != None) & (prise != 50) : # si port 50 (uplink, on affiche rien)
self.tableau.append("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), sw.nom(None, prise))) self.reponse = ("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), sw.nom(None, prise)))
# interrogation des switchs en parallele # interrogation des switchs en parallele
def get_trace(mac): def get_trace(mac):
@ -39,15 +39,21 @@ def get_trace(mac):
tableau=[] tableau=[]
for switch in ['backbone'] + all_switchs(): for switch in ['backbone'] + all_switchs():
interroge_switch(tableau,switch, mac) tableau.append(interroge_switch(switch, mac))
while len(threading.enumerate()) > 1 : while len(threading.enumerate()) > 1 :
sleep(1) sleep(1)
resultat ='tracage de %s\n' % mac resultat ='tracage de %s\n' % mac
resultat += '\n'.join(tableau)
return resultat tracage=''
for t in tableau:
if t.reponse:
tracage += t.reponse +"\n"
if tracage=='':
tracage = "mac inconnue des switchs"
return (resultat + tracage)
# on interroge les switchs et on fait un whos sur la mac # on interroge les switchs et on fait un whos sur la mac
if __name__ == '__main__': if __name__ == '__main__':