Export AS <--> net data for ROA via API

Also includes a small cli tool
This commit is contained in:
Sebastian Lohff 2018-01-21 18:26:20 +01:00
parent 43fb65dd6d
commit 7c5ddfc6ee
3 changed files with 62 additions and 0 deletions

View File

@ -14,4 +14,6 @@ urlpatterns = [
url(r'domain/check/$', api_views.checkDomain, name='domain-check'), url(r'domain/check/$', api_views.checkDomain, name='domain-check'),
url(r'rzone/check/$', api_views.checkRzone, name='reversezone-check'), url(r'rzone/check/$', api_views.checkRzone, name='reversezone-check'),
url(r'roa/$', api_views.getROA, name='get-roa'),
] ]

View File

@ -222,3 +222,16 @@ def checkRzone(request):
ret["errorMsg"] = "ReverseZone does not exist" ret["errorMsg"] = "ReverseZone does not exist"
return JsonResponse(ret) return JsonResponse(ret)
def getROA(request):
roa = {}
for asn in ASNumber.objects.all():
nets = []
for net in asn.inetnum_set.all():
nets.append(net.prefix())
if nets:
roa[asn.number] = nets
return JsonResponse(roa)

47
bin/roa-export Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This file is part of dnmgmt, a number resource management system
# Licensed under GNU General Public License v3 or later
# Written by Sebastian Lohff (seba@someserver.de)
import argparse
import json
import sys
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dnmgmt.settings")
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
django.setup()
from whoisdb.models import ASNumber
__VERSION__ = '0.1'
def _parser():
parser = argparse.ArgumentParser()
parser.add_argument("--version", action="version", version="%(prog)s " + __VERSION__)
return parser
def main():
parser = _parser()
parser.parse_args()
roa = {}
for asn in ASNumber.objects.all():
nets = []
for net in asn.inetnum_set.all():
nets.append(net.prefix())
if nets:
roa[asn.number] = nets
print(json.dumps(roa))
if __name__ == '__main__':
main()