adding code for RDAP and TLD websites

This commit is contained in:
Arnold Dechamps 2024-04-14 17:47:19 +02:00
parent 1b9115b1f5
commit 0ac8a1e9c7
No known key found for this signature in database
GPG key ID: AE66543374E41C89
2 changed files with 45 additions and 3 deletions

View file

@ -37,6 +37,8 @@ class TLD(models.Model):
amountofkeys = models.IntegerField(default=0) amountofkeys = models.IntegerField(default=0)
lastEdition = models.DateTimeField(auto_now=True) lastEdition = models.DateTimeField(auto_now=True)
organisation = models.CharField(max_length=100) organisation = models.CharField(max_length=100)
rdap = models.CharField(max_length=10, default="No")
link = models.CharField(max_length=800, default="https://tldtest.net/")
def __str__(self): def __str__(self):
return self.tld return self.tld

View file

@ -3,6 +3,7 @@ This file is dumping the IANA root zone and sorting it in the database
Link to IANA website : https://www.internic.net/domain/root.zone Link to IANA website : https://www.internic.net/domain/root.zone
""" """
import json import json
import config
import urllib.request import urllib.request
from tldtester.models import TLD, RootZone from tldtester.models import TLD, RootZone
from django.core.exceptions import MultipleObjectsReturned from django.core.exceptions import MultipleObjectsReturned
@ -44,6 +45,8 @@ def zonesorter(zonefile):
Takes the zonefile as an input and writes the records to the database Takes the zonefile as an input and writes the records to the database
""" """
for line in zonefile: for line in zonefile:
if config.DEBUG is True:
print(line)
value = "" value = ""
record = line.split() record = line.split()
if len(record) >= 5: if len(record) >= 5:
@ -56,6 +59,8 @@ def zonesorter(zonefile):
value = value + record[i + 4] + " " value = value + record[i + 4] + " "
towrite = {"name": name, "type": recordtype, "value": value} towrite = {"name": name, "type": recordtype, "value": value}
zonedbwriter(towrite) zonedbwriter(towrite)
if config.DEBUG is True:
print("Done Parsing the Zones")
def zonedbwriter(recs): def zonedbwriter(recs):
@ -85,20 +90,25 @@ def tlddbwriter(recs):
db.dnssec = recs["algo"] db.dnssec = recs["algo"]
db.amountofkeys = recs["amountofkeys"] db.amountofkeys = recs["amountofkeys"]
db.organisation = recs["organisation"] db.organisation = recs["organisation"]
db.link = recs["link"]
db.rdap = recs["rdap"]
db.save() db.save()
def grabber(data): def grabber(data, rdaptlds):
""" """
This function takes the TLD's and makes querrys to the DNS. It looks up how many authoritative DNS's there are and This function takes the TLD's and makes querrys to the DNS. It looks up how many authoritative DNS's there are and
analyses the v4, v6 and DNSSEC. Returns a list of dictionaries with all the vallues to write in the database analyses the v4, v6 and DNSSEC. Returns a list of dictionaries with all the vallues to write in the database
""" """
for tld in data: for tld in data:
if config.DEBUG is True:
print("starting with " + tld)
nsservers = [] nsservers = []
dnsseckeys = [] dnsseckeys = []
Arecords = 0 Arecords = 0
AAAArecords = 0 AAAArecords = 0
amountofkeys = 0 amountofkeys = 0
link = "https://tldtest.net"
nses = RootZone.objects.all().filter(name=tld + ".", rectype="NS") nses = RootZone.objects.all().filter(name=tld + ".", rectype="NS")
for ns in nses: for ns in nses:
nsservers.append(ns.value) nsservers.append(ns.value)
@ -154,23 +164,53 @@ def grabber(data):
organisation = entity["vcardArray"][1][2][3] organisation = entity["vcardArray"][1][2][3]
except: except:
organisation = "Reserved" organisation = "Reserved"
try:
link = data["links"][2]["href"]
except Exception as e:
print("link not found for " + tld)
print(e)
if tld in rdaptlds:
rdap = "Yes"
else:
rdap = "No"
results = {"tld": tld, "unicodeTld": unicodetld, "nsserveramount": int(len((nsservers))), results = {"tld": tld, "unicodeTld": unicodetld, "nsserveramount": int(len((nsservers))),
"organisation": organisation, "v4resolvers": Arecords, "v6resolvers": AAAArecords, "algo": algo, "organisation": organisation, "v4resolvers": Arecords, "v6resolvers": AAAArecords, "algo": algo,
"amountofkeys": amountofkeys} "amountofkeys": amountofkeys, "link": link, "rdap": rdap}
if config.DEBUG is True:
print(results)
tlddbwriter(results) tlddbwriter(results)
def rdaper():
"""
Downloads the root zone (as to not put constraint on the DNSses and resolve locally). Returns the zonefile in lines.
returns None if not working.
"""
rdaptlds = []
url = urllib.request.urlopen("https://data.iana.org/rdap/dns.json")
if url.getcode() == 200:
raw = url.read()
raw = raw.decode("utf-8")
else:
raw = None
data = json.loads(raw)
for i in data["services"]:
for j in i[0]:
rdaptlds.append(j)
return rdaptlds
def main(): def main():
try: try:
zonefile = zonedownloader().splitlines(True) zonefile = zonedownloader().splitlines(True)
rdaptlds = rdaper()
if zonefile is not None: if zonefile is not None:
# First delete the entire zone database if file polling is successful and re write # First delete the entire zone database if file polling is successful and re write
RootZone.objects.all().delete() RootZone.objects.all().delete()
zonesorter(zonefile) zonesorter(zonefile)
tlds = tlddownloader() tlds = tlddownloader()
if tlds is not None: if tlds is not None:
grabber(tlds) grabber(tlds, rdaptlds)
except Exception as e: except Exception as e:
print(e) print(e)