class fakeVPS: def __init__(self): pass def sync(self): pass class monitor: def __init__(self): self.cap = pycap.capture.capture() self.cap.filter("host not 64.62.166.222") self.oldtime = time.time() self.vDict={} self.runs=0 def go(self): while True: if time.time()-self.oldtime>10: for i in self.vDict: print "updated: %s with %s" % ( self.vDict[i].name, self.vDict[i].input) self.vDict[i].sync() self.oldtime=time.time() if self.runs==100: self.vDict={} self.runs=0 packet = self.cap.next() if hasattr(packet[1], "destination") and hasattr(packet[1], "source"): if not self.vDict.has_key(packet[1].destination) and not self.vDict.has_key(packet[1].source): for i in db.VPS.select(): if packet[1].destination in i.saneIP(): self.vDict[packet[1].destination]=i break elif packet[1].source in i.saneIP(): self.vDict[packet[1].source]=i break if self.vDict.has_key(packet[1].destination): self.vDict[packet[1].destination].input=self.vDict[packet[1].destination].input+packet[1].length elif self.vDict.has_key(packet[1].source): self.vDict[packet[1].source].output=self.vDict[packet[1].source].output+packet[1].length else: print "Lost packet with length %s, from %s to %s" % (packet[1].length, packet[1].source, packet[1].destination) while True: try: monitor().go() except: print "Crap"