dnmgmt/bin/roa-export

48 lines
1020 B
Python
Executable File

#!/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()