def query_dquad(self, dquad): num = dq_to_num(dquad) plen = 0 masks = self.masks bt = self.bt for i in range(32,-1,-1): masked_num = num & masks[i] if bt[i].has_key(masked_num): return (bt[i][masked_num], i, masked_num, num) return (0,0,0,0)
def query_dquad(self, dquad): print "--- running ASNumRealLookup.query_dquad" print dquad num = dq_to_num(dquad) plen = 0 masks = self.masks bt = self.bt for i in range(32,-1,-1): masked_num = num & masks[i] if bt[i].has_key(masked_num): return (bt[i][masked_num], i, masked_num, num) return (0,0,0,0)
def parse_line_pair(self, genericness, line1, line2): """parse a line pair from a whois network summary query to ARIN. line1 holds the OrgName, NetName and, in parentheses, NetHandle. line2 holds the NetRange preceeded by a run of blanks.""" l1_parts=string.strip(line1).split(" ") net_range=[s for s in line2.split(" ") if len(s) > 1] #print l1_parts OrgName=" ".join(l1_parts[:-2]) NetName=l1_parts[-2] NetHandle=l1_parts[-1][1:-1] if self.verbose: print "OrgName=%s NetName=%s NetHandle=%s NetRange=%s - %s" % (OrgName, NetName, NetHandle, net_range[0], net_range[1]) range_id = self.req.put_range(genericness, OrgName, NetName, NetHandle, net_range[0], net_range[1]) n_start = dq_to_num(net_range[0]) n_end = dq_to_num(net_range[1]) #print "%08x %08x" % (n_start, n_end) # 108.0.0.0 - 108.57.191.255 is a good example of where we need CIDR pl=nr_to_cidr(n_start, n_end) for p in pl: dquad = num_to_dq(p[0]) if self.verbose: print "CIDR: %s/%d" % (dquad, p[1]) self.req.put_cidr(range_id, dquad, p[1])
def __init__(self, bgp_table): po=re.compile("^([0-9.]+)/([0-9]+) ([0-9_]+)$") masks=[(0xffffffff&((-1)<<i)) for i in range(32,-1,-1)] bt=[None]*33 for i in range(33): bt[i] = {} fd = open(bgp_table) while True: line = fd.readline() if len(line) == 0: break mo = po.match(line) if mo: (pfx, plen, asn) = mo.groups() plen = int(plen) pfxbin = dq_to_num(pfx) & masks[plen] bt[plen][pfxbin] = asn fd.close() self.masks = masks self.bt = bt
show_chotels = True elif flag == '-Z': do_debug = True elif flag == '-u': do_update_ip_addr_info = True ml = MaxMindLookup('A') #al = ASNumRealLookup("tiny_bgp.txt") #al = ASNumRealLookup("origin_as_mapping.txt") al = ASNumSockLookup("A") if do_virtual_traceroute: tr_elems = [s.split(",") for s in args] if do_debug: print tr_elems tr = [TRNode(dq_to_num(t[0]), float(t[1])) for t in tr_elems] if do_debug: print tr if show_interests: interests = create_from_file({}, InterestAttribute.factory, "interests.txt") print interests if show_owners: owners = create_from_file({}, CHOwner.factory, "owners.txt") print owners if show_chotels: chotels = create_from_file({}, CHotel.factory, "chotels.txt") print chotels for tr_elem in tr: tr_elem.lookup_geoloc(ml) #print al.query_dquad(tr_elem.dquad)