nettoyage + threading plus propre
darcs-hash:20061007005209-f6463-72a15b48ee8b83826945ff33b154e89122995e31.gz
This commit is contained in:
parent
dfeabde3b1
commit
78b289e130
1 changed files with 13 additions and 7 deletions
|
@ -16,11 +16,11 @@ def format_mac(unformated_mac):
|
|||
|
||||
# classe d'interrogation des switchs
|
||||
class interroge_switch (threading.Thread) :
|
||||
def __init__ (self, tableau, switch, mac = None) :
|
||||
def __init__ (self, switch, mac = None) :
|
||||
threading.Thread.__init__(self)
|
||||
self.tableau=tableau
|
||||
self.switch = switch
|
||||
self.mac = mac
|
||||
self.reponse=None
|
||||
self.start()
|
||||
|
||||
def run (self) :
|
||||
|
@ -30,8 +30,8 @@ class interroge_switch (threading.Thread) :
|
|||
while (prise==None) & (iteration > 0):
|
||||
prise = sw.where_is_mac(self.mac)
|
||||
iteration = iteration-1
|
||||
if prise != None :
|
||||
self.tableau.append("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), sw.nom(None, prise)))
|
||||
if (prise != None) & (prise != 50) : # si port 50 (uplink, on affiche rien)
|
||||
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
|
||||
def get_trace(mac):
|
||||
|
@ -39,15 +39,21 @@ def get_trace(mac):
|
|||
tableau=[]
|
||||
|
||||
for switch in ['backbone'] + all_switchs():
|
||||
interroge_switch(tableau,switch, mac)
|
||||
tableau.append(interroge_switch(switch, mac))
|
||||
|
||||
while len(threading.enumerate()) > 1 :
|
||||
sleep(1)
|
||||
|
||||
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
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue