Export AS <--> net data for ROA via API
Also includes a small cli tool
This commit is contained in:
parent
43fb65dd6d
commit
7c5ddfc6ee
|
@ -14,4 +14,6 @@ urlpatterns = [
|
|||
url(r'domain/check/$', api_views.checkDomain, name='domain-check'),
|
||||
url(r'rzone/check/$', api_views.checkRzone, name='reversezone-check'),
|
||||
|
||||
url(r'roa/$', api_views.getROA, name='get-roa'),
|
||||
|
||||
]
|
||||
|
|
13
api/views.py
13
api/views.py
|
@ -222,3 +222,16 @@ def checkRzone(request):
|
|||
ret["errorMsg"] = "ReverseZone does not exist"
|
||||
|
||||
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)
|
||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue