def contarHosts(dump): #perdón por el copy-paste f = open(dump, 'r') filtrarWhos = lambda l: l and l.split()[0] == '1' #Leemos sólo los who-has l = parser.readFilteredLine(f, filtrarWhos) #Cantidad: dicc(ipDst => cantidadDeApariciones) cantidad = collections.Counter() while l: l = l.split() cantidad[l[1]] += 1 #si la clave k no está definida, cantidad[k] = 0 l = parser.readFilteredLine(f, filtrarWhos) return cantidad
def contarSimbolos(dump, startTime = None, endTime = None): f = open(dump, 'r') startEndFilter = lambda l: parser.filtrarPorTiempo(l, startTime, endTime) #Leemos sólo las líneas que pasan el filtro startEndFilter (ver parser.py) l = parser.readFilteredLine(f, startEndFilter) #Cantidad: dicc((ipSrc, ipDst) => cantidadDeApariciones) cantidad = collections.Counter() while l: l = l.split() #Normalizamos el par (ipSrc, ipDst) como el string que resulta de concatenarlos para poder usarlos de índice: norm((ipSrc, ipDst)) = ipSrc-ipDst #Es claro que resulta (ipSrc, ipDst) = (iprc', ipDst') <=> norm(ipSrc, ipDst) = norm(ipSrc', ipDst') cantidad[l[1]+'-'+l[2]] += 1 #si la clave k no está definida, cantidad[k] = 0 l = parser.readFilteredLine(f, startEndFilter) return cantidad