def __init__ \ ( self , olsr_file , processes = 20 , N = 0 , timeout = 180 , ip_port = {} , debug = False , ** kw ) : self.__super.__init__ (**kw) olsr = get_olsr_container (olsr_file) self.olsr_nodes = {} assert len (olsr.topo.forward) for t in olsr.topo.forward.iterkeys () : self.olsr_nodes [t] = True for t in olsr.topo.reverse.iterkeys () : self.olsr_nodes [t] = True # limit to N elements if N : self.olsr_nodes = dict \ ((k, v) for k, v in islice (self.olsr_nodes.iteritems (), N)) self.pool = Pool (processes = processes) self.mgr = Manager () self.result_dict = self.mgr.dict () self.timeout = timeout self.ip_port = ip_port self.debug = debug olsr_nodes = None if not debug : self.log.setLevel (INFO) self.log.debug ("Starting ...")
def __init__ (self, cmd, scope, debug = False) : self.debug = debug self.verbose = cmd.verbose self.anonymize = cmd.anonymize if len (cmd.argv) > 0 : f = open (cmd.argv [0]) else : f = sys.stdin self.ip4nets = {} self.ip6nets = {} if cmd.network : for n in cmd.network : ip, comment = n.split (';', 1) if ':' in ip : ip = IP6_Address (ip) self.ip6nets [ip] = comment else : ip = IP4_Address (ip) self.ip4nets [ip] = comment olsr = get_olsr_container (cmd.olsr_file) self.olsr_nodes = {} for t in olsr.topo.forward.iterkeys () : self.olsr_nodes [t] = True for t in olsr.topo.reverse.iterkeys () : self.olsr_nodes [t] = True self.olsr_mid = olsr.mid.by_ip self.olsr_hna = olsr.hna self.rev_mid = {} for k, v in self.olsr_mid.iteritems () : if k not in self.olsr_nodes : pyk.fprint ("WARN: MIB %s: not in OLSR Topology" % k) #assert k in self.olsr_nodes for mid in v : assert mid not in self.rev_mid self.rev_mid [mid] = True self.spider_info = pickle.load (open (cmd.spider_dump, 'rb')) self.spider_devs = {} self.spider_iface = {} for ip, dev in self.spider_info.iteritems () : if self.verbose : pyk.fprint ("IP:", ip) # ignore spider errors if not isinstance (dev, Guess) : continue dev.mainip = ip dev.done = False for iface in dev.interfaces.itervalues () : iface.done = False for ip4 in iface.inet4 : i4 = ip4.ip # ignore rfc1918, link local, localnet if unroutable (i4) : continue if ( i4 in self.spider_devs and self.spider_devs [i4] != dev ) : pyk.fprint ("WARN: Device %s/%s not equal:" % (ip, i4)) pyk.fprint ("=" * 60) pyk.fprint (dev.verbose_repr ()) pyk.fprint ("-" * 60) pyk.fprint (self.spider_devs [i4].verbose_repr ()) pyk.fprint ("=" * 60) elif ( i4 in self.spider_iface and self.spider_iface [i4] != iface ) : assert dev == self.spider_devs [i4] spif = self.spider_iface [i4] pyk.fprint \ ( "WARN: Interfaces %s/%s of dev-ip %s share ip %s" % (iface.name, spif.name, ip, i4) ) spif.names.append (iface.name) if iface.is_wlan : spif.is_wlan = iface.is_wlan spif.wlan_info = getattr (iface, 'wlan_info', None) if self.verbose : pyk.fprint ("=" * 60) pyk.fprint (iface) pyk.fprint (spif) pyk.fprint ("-" * 60) pyk.fprint (dev.verbose_repr ()) pyk.fprint ("=" * 60) iface = spif self.spider_devs [i4] = dev self.spider_iface [i4] = iface iface.device = dev if ip not in self.spider_devs : pyk.fprint ("WARN: ip %s not in dev" % ip) if self.verbose : pyk.fprint ("=" * 60) pyk.fprint (dev.verbose_repr ()) pyk.fprint ("=" * 60) name = 'unknown' assert name not in dev.interfaces iface = Interface (4711, name) iface.done = False dev.interfaces [name] = iface iface.device = dev iface.append_inet4 (Inet4 (ip, None, None, iface = name)) self.spider_iface [ip] = iface self.spider_devs [ip] = dev self.scope = scope self.ffm = self.scope.FFM self.pap = self.scope.GTW.OMP.PAP self.mentor = {} self.rsrvd_nets = {} self.ffm_node_by_id = {} self.node_by_id = {} self.ip_by_ip = {} self.email_ids = {} self.phone_ids = {} self.person_by_id = {} self.member_by_id = {} self.dev_by_node = {} self.cons_dev = {} self.parser = SQL_Parser \ (verbose = False, fix_double_encode = True) self.parser.parse (f) self.contents = self.parser.contents self.tables = self.parser.tables
def __init__(self, cmd, scope, debug=False): self.debug = debug self.verbose = cmd.verbose self.anonymize = cmd.anonymize if len(cmd.argv) > 0: f = open(cmd.argv[0]) else: f = sys.stdin self.ip4nets = {} self.ip6nets = {} if cmd.network: for n in cmd.network: ip, comment = n.split(';', 1) if ':' in ip: ip = IP6_Address(ip) self.ip6nets[ip] = comment else: ip = IP4_Address(ip) self.ip4nets[ip] = comment olsr = get_olsr_container(cmd.olsr_file) self.olsr_nodes = {} for t in olsr.topo.forward.iterkeys(): self.olsr_nodes[t] = True for t in olsr.topo.reverse.iterkeys(): self.olsr_nodes[t] = True self.olsr_mid = olsr.mid.by_ip self.olsr_hna = olsr.hna self.rev_mid = {} for k, v in self.olsr_mid.iteritems(): if k not in self.olsr_nodes: pyk.fprint("WARN: MIB %s: not in OLSR Topology" % k) #assert k in self.olsr_nodes for mid in v: assert mid not in self.rev_mid self.rev_mid[mid] = True self.spider_info = pickle.load(open(cmd.spider_dump, 'rb')) self.spider_devs = {} self.spider_iface = {} for ip, dev in self.spider_info.iteritems(): if self.verbose: pyk.fprint("IP:", ip) # ignore spider errors if not isinstance(dev, Guess): continue dev.mainip = ip dev.done = False for iface in dev.interfaces.itervalues(): iface.done = False for ip4 in iface.inet4: i4 = ip4.ip # ignore rfc1918, link local, localnet if unroutable(i4): continue if (i4 in self.spider_devs and self.spider_devs[i4] != dev): pyk.fprint("WARN: Device %s/%s not equal:" % (ip, i4)) pyk.fprint("=" * 60) pyk.fprint(dev.verbose_repr()) pyk.fprint("-" * 60) pyk.fprint(self.spider_devs[i4].verbose_repr()) pyk.fprint("=" * 60) elif (i4 in self.spider_iface and self.spider_iface[i4] != iface): assert dev == self.spider_devs[i4] spif = self.spider_iface[i4] pyk.fprint \ ( "WARN: Interfaces %s/%s of dev-ip %s share ip %s" % (iface.name, spif.name, ip, i4) ) spif.names.append(iface.name) if iface.is_wlan: spif.is_wlan = iface.is_wlan spif.wlan_info = getattr(iface, 'wlan_info', None) if self.verbose: pyk.fprint("=" * 60) pyk.fprint(iface) pyk.fprint(spif) pyk.fprint("-" * 60) pyk.fprint(dev.verbose_repr()) pyk.fprint("=" * 60) iface = spif self.spider_devs[i4] = dev self.spider_iface[i4] = iface iface.device = dev if ip not in self.spider_devs: pyk.fprint("WARN: ip %s not in dev" % ip) if self.verbose: pyk.fprint("=" * 60) pyk.fprint(dev.verbose_repr()) pyk.fprint("=" * 60) name = 'unknown' assert name not in dev.interfaces iface = Interface(4711, name) iface.done = False dev.interfaces[name] = iface iface.device = dev iface.append_inet4(Inet4(ip, None, None, iface=name)) self.spider_iface[ip] = iface self.spider_devs[ip] = dev self.scope = scope self.ffm = self.scope.FFM self.pap = self.scope.GTW.OMP.PAP self.mentor = {} self.rsrvd_nets = {} self.ffm_node_by_id = {} self.node_by_id = {} self.ip_by_ip = {} self.email_ids = {} self.phone_ids = {} self.person_by_id = {} self.member_by_id = {} self.dev_by_node = {} self.cons_dev = {} self.parser = SQL_Parser \ (verbose = False, fix_double_encode = True) self.parser.parse(f) self.contents = self.parser.contents self.tables = self.parser.tables