def query_view(request): """ Allow the user to search for an AS or prefix, and show all published ROA information. """ if request.method == 'POST': form = forms.SearchForm(request.POST, request.FILES) if form.is_valid(): certs = None roas = None addr = form.cleaned_data.get('addr') asn = form.cleaned_data.get('asn') if addr: family, r = misc.parse_ipaddr(addr) prefixes = models.ROAPrefix.objects.filter(family=family, prefix=str(r.min)) prefix_list = [] for pfx in prefixes: for roa in pfx.roas.all(): prefix_list.append((pfx, roa)) elif asn: r = resource_range_as.parse_str(asn) roas = models.ROA.objects.filter(asid__gte=r.min, asid__lte=r.max) # display the results sorted by prefix prefix_list = [] for roa in roas: for pfx in roa.prefixes.all(): if pfx.family == 4: addr = v4addr(pfx.prefix.encode()) elif pfx.family == 6: addr = v6addr(pfx.prefix.encode()) prefix_list.append((pfx, roa, addr)) prefix_list.sort(cmp=cmp_prefix) return render('cacheview/query_result.html', { 'object_list': prefix_list }, request) else: form = forms.SearchForm() return render('cacheview/search_form.html', { 'form':form, 'search_type': 'ROA ' }, request)
line = line.rstrip() if not line.startswith("apnic|") or line.endswith("|summary"): continue try: registry, cc, rectype, start, value, date, status, opaque_id = line.split( "|") except ValueError: continue if not opaque_id: continue assert registry == "apnic" if rectype == "asn": asns.writerow( (opaque_id, "%s-%s" % (start, int(start) + int(value) - 1))) elif rectype == "ipv4": prefixes.writerow( (opaque_id, "%s-%s" % (start, v4addr(v4addr(start) + long(value) - 1)))) elif rectype == "ipv6": prefixes.writerow((opaque_id, "%s/%s" % (start, value))) asns.close() prefixes.close()
from rpki.resource_set import roa_prefix_ipv4, resource_set_ipv4, resource_range_ipv4 roas = [] for filename in sys.argv[1:]: resources = rpki.x509.X509(Auto_file=filename).get_3779resources().v4 while resources: labels = str(resources[0].min).split(".") labels.reverse() try: for answer in dns.resolver.query( ".".join(labels) + ".asn.routeviews.org", "txt"): asn, prefix, prefixlen = answer.strings roa_prefix = roa_prefix_ipv4(v4addr(prefix), long(prefixlen)) roa = "%s\t%s\t%s" % (roa_prefix, long(asn), filename) if roa not in roas: roas.append(roa) resources = resources.difference( resource_set_ipv4([roa_prefix.to_resource_range()])) except dns.resolver.NXDOMAIN: resources = resources.difference( resource_set_ipv4([ resource_range_ipv4(resources[0].min, v4addr(resources[0].min + 256)) ])) roas.sort()
prefixes = csv_writer("prefixes.csv") for line in open("delegated-apnic-extended-latest"): line = line.rstrip() if not line.startswith("apnic|") or line.endswith("|summary"): continue try: registry, cc, rectype, start, value, date, status, opaque_id = line.split("|") except ValueError: continue if not opaque_id: continue assert registry == "apnic" if rectype == "asn": asns.writerow((opaque_id, "%s-%s" % (start, int(start) + int(value) - 1))) elif rectype == "ipv4": prefixes.writerow((opaque_id, "%s-%s" % (start, v4addr(v4addr(start) + long(value) - 1)))) elif rectype == "ipv6": prefixes.writerow((opaque_id, "%s/%s" % (start, value))) asns.close() prefixes.close()
import dns.resolver import rpki.x509 from rpki.ipaddrs import v4addr from rpki.resource_set import roa_prefix_ipv4, resource_set_ipv4, resource_range_ipv4 roas = [] for filename in sys.argv[1:]: resources = rpki.x509.X509(Auto_file = filename).get_3779resources().v4 while resources: labels = str(resources[0].min).split(".") labels.reverse() try: for answer in dns.resolver.query(".".join(labels) + ".asn.routeviews.org", "txt"): asn, prefix, prefixlen = answer.strings roa_prefix = roa_prefix_ipv4(v4addr(prefix), long(prefixlen)) roa = "%s\t%s\t%s" % (roa_prefix, long(asn), filename) if roa not in roas: roas.append(roa) resources = resources.difference(resource_set_ipv4([roa_prefix.to_resource_range()])) except dns.resolver.NXDOMAIN: resources = resources.difference(resource_set_ipv4([resource_range_ipv4(resources[0].min, v4addr(resources[0].min + 256))])) roas.sort() for roa in roas: print roa