From b8392ae78199bdc7d9929db94c1c17b2a04286d6 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Sun, 11 Oct 2009 04:41:24 +0200 Subject: [PATCH] =?UTF-8?q?[hptools]=20On=20contourne=20les=20macs=20ind?= =?UTF-8?q?=C3=A9licates=20(genre=20"ord(r):ord(a):ord(d):ord(i):ord(u):or?= =?UTF-8?q?d(s)")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore-this: 41ab1e2013da859fbbe7965565191e77 darcs-hash:20091011024124-ffbb2-9d9b652c0b9aee1a68acc16c1b8dd0cd975b27b9.gz --- gestion/hptools.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gestion/hptools.py b/gestion/hptools.py index 68e08cfc..ec416e91 100644 --- a/gestion/hptools.py +++ b/gestion/hptools.py @@ -224,7 +224,15 @@ class hpswitch : if self.__debug : self.__logDest.write("HP DEBUG : show_prise_mac(prise=%s)\n" % prise) try: data = self.walk('STATISTICS-MIB::hpSwitchPortFdbAddress.%d' % int(prise)) - return map(lambda x:findall('".*"',":".join(x.lower().split(' ')))[0][1:-2],data.values()) + macs = [] + for value in data.itervalues(): + mac = findall('".*"', value)[0][1:-1] + if ' ' in mac: + macs.append(":".join(mac.lower().split(" "))) + else: + macs.append(":".join("%02x" % ord(digit) for digit in mac)) + print macs + return macs except ValueError: # Pas de MAC trouvée return [] @@ -243,7 +251,10 @@ class hpswitch : # On cherche dans data la bonne adresse MAC for (onesnmp, onemac) in data.iteritems(): - if onemac[1:-2] == mac: + onemac = findall('".*"', onemac)[0][1:-1] + if ' ' not in onemac: + onemac = " ".join("%02x" % ord(digit) for digit in mac) + if onemac.startswith(mac): return int(onesnmp.split(".")[1]) # On a rien trouvé