Rparation du locate_mac pour arpwatch.

darcs-hash:20070403070720-68412-446e4c05d16b85114c37d278048a0cbd60e88f55.gz
This commit is contained in:
glondu 2007-04-03 09:07:20 +02:00
parent 766afb47c2
commit a071b36369

View file

@ -19,11 +19,12 @@ 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, switch, mac = None) : def __init__ (self, switch, mac=None, affiche_uplinks=False):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.switch = switch self.switch = switch
self.mac = mac self.mac = mac
self.reponse = None self.reponse = None
self.affiche_uplinks = affiche_uplinks
self.start() self.start()
def run (self) : def run (self) :
@ -35,7 +36,7 @@ class interroge_switch (threading.Thread) :
iteration = iteration-1 iteration = iteration-1
if (prise != None): if (prise != None):
nom=sw.nom(None,prise) nom=sw.nom(None,prise)
if affiche_uplinks or "uplink" not in nom: if self.affiche_uplinks or "uplink" not in nom:
self.reponse = ("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), nom)) self.reponse = ("%-10s => prise %-2s : %s" % (self.switch.encode('iso-8859-15').replace('.adm.crans.org',''), str(prise), nom))
@ -56,11 +57,11 @@ def info_machine(mac):
# interrogation des switchs en parallele # interrogation des switchs en parallele
def trace_machine(mac): def trace_machine(mac, affiche_uplinks=False):
tableau = [] tableau = []
for switch in ['backbone','multiprise'] + all_switchs(): for switch in ['backbone','multiprise'] + all_switchs():
tableau.append(interroge_switch(switch, mac)) tableau.append(interroge_switch(switch, mac, affiche_uplinks))
for t in tableau: for t in tableau:
t.join() t.join()
@ -81,5 +82,5 @@ def trace_machine(mac):
if __name__ == '__main__': if __name__ == '__main__':
mac = format_mac(sys.argv[1]) mac = format_mac(sys.argv[1])
affiche_uplinks = len(sys.argv) > 2 and bool(sys.argv[2]) affiche_uplinks = len(sys.argv) > 2 and bool(sys.argv[2])
print trace_machine(mac) print trace_machine(mac, affiche_uplinks)
print system('/usr/scripts/gestion/whos.py -a mac=%s' % mac) print system('/usr/scripts/gestion/whos.py -a mac=%s' % mac)