dnmgmt/bin/roa-export

48 lines
1020 B
Plaintext
Raw Normal View History

#!/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():
2019-05-30 22:10:55 +02:00
parser = argparse.ArgumentParser()
2019-05-30 22:10:55 +02:00
parser.add_argument("--version", action="version", version="%(prog)s " + __VERSION__)
2019-05-30 22:10:55 +02:00
return parser
def main():
2019-05-30 22:10:55 +02:00
parser = _parser()
parser.parse_args()
2019-05-30 22:10:55 +02:00
roa = {}
for asn in ASNumber.objects.all():
nets = []
for net in asn.inetnum_set.all():
nets.append(net.prefix())
2019-05-30 22:10:55 +02:00
if nets:
roa[asn.number] = nets
2019-05-30 22:10:55 +02:00
print(json.dumps(roa))
if __name__ == '__main__':
2019-05-30 22:10:55 +02:00
main()