Browse Source

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

Also includes a small cli tool
Sebastian Lohff 1 year ago
parent
commit
7c5ddfc6ee
3 changed files with 62 additions and 0 deletions
  1. 2
    0
      api/urls.py
  2. 13
    0
      api/views.py
  3. 47
    0
      bin/roa-export

+ 2
- 0
api/urls.py View File

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

+ 13
- 0
api/views.py View File

@@ -222,3 +222,16 @@ def checkRzone(request):
222 222
 		ret["errorMsg"] = "ReverseZone does not exist"
223 223
 
224 224
 	return JsonResponse(ret)
225
+
226
+
227
+def getROA(request):
228
+	roa = {}
229
+	for asn in ASNumber.objects.all():
230
+		nets = []
231
+		for net in asn.inetnum_set.all():
232
+			nets.append(net.prefix())
233
+
234
+		if nets:
235
+			roa[asn.number] = nets
236
+
237
+	return JsonResponse(roa)

+ 47
- 0
bin/roa-export View File

@@ -0,0 +1,47 @@
1
+#!/usr/bin/env python3
2
+# -*- coding: utf-8 -*-
3
+# This file is part of dnmgmt, a number resource management system
4
+# Licensed under GNU General Public License v3 or later
5
+# Written by Sebastian Lohff (seba@someserver.de)
6
+
7
+import argparse
8
+import json
9
+
10
+import sys
11
+import os
12
+import django
13
+
14
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dnmgmt.settings")
15
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
16
+sys.path.append(BASE_DIR)
17
+django.setup()
18
+
19
+
20
+from whoisdb.models import ASNumber
21
+
22
+__VERSION__ = '0.1'
23
+
24
+def _parser():
25
+	parser = argparse.ArgumentParser()
26
+
27
+	parser.add_argument("--version", action="version", version="%(prog)s " + __VERSION__)
28
+
29
+	return parser
30
+
31
+def main():
32
+	parser = _parser()
33
+	parser.parse_args()
34
+
35
+	roa = {}
36
+	for asn in ASNumber.objects.all():
37
+		nets = []
38
+		for net in asn.inetnum_set.all():
39
+			nets.append(net.prefix())
40
+
41
+		if nets:
42
+			roa[asn.number] = nets
43
+
44
+	print(json.dumps(roa))
45
+
46
+if __name__ == '__main__':
47
+	main()

Loading…
Cancel
Save