Skip to content

Commit

Permalink
passed on zonefile instead of active DNS-Polling
Browse files Browse the repository at this point in the history
  • Loading branch information
altf4arnold committed Feb 26, 2024
1 parent 3ba7da8 commit 323db5f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 43 deletions.
1 change: 0 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ build==1.0.3
click==8.1.7
Django==5.0.2
django-admin-extra-buttons==1.5.7
dnspython==2.6.1
flake8==7.0.0
mccabe==0.7.0
packaging==23.2
Expand Down
11 changes: 8 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.in
Expand All @@ -20,8 +20,6 @@ django==5.0.2
# via -r requirements.in
django-admin-extra-buttons==1.5.7
# via -r requirements.in
dnspython==2.6.1
# via -r requirements.in
flake8==7.0.0
# via -r requirements.in
mccabe==0.7.0
Expand Down Expand Up @@ -50,6 +48,13 @@ sqlparse==0.4.4
# via
# -r requirements.in
# django
tomli==2.0.1
# via
# build
# pip-tools
# pyproject-hooks
typing-extensions==4.10.0
# via asgiref
wheel==0.42.0
# via pip-tools

Expand Down
1 change: 1 addition & 0 deletions tldtester/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TLD(models.Model):
v4nsamount = models.IntegerField(default=0)
v6nsamount = models.IntegerField(default=0)
dnssec = models.IntegerField(default=300, choices=DNSSECALGOS)
amountofkeys = models.IntegerField(default=0)
lastEdition = models.DateTimeField(auto_now=True)

def __str__(self):
Expand Down
77 changes: 38 additions & 39 deletions tldtester/sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import urllib.request
from tldtester.models import TLD, RootZone
import dns.resolver
from django.core.exceptions import MultipleObjectsReturned


def zonedownloader():
Expand All @@ -31,6 +31,8 @@ def tlddownloader():
raw = raw.decode("utf-8").splitlines()
# File has a timestamp as first line. This will take it out so we only keep the TLD's
raw.pop(0)
for i in range(len(raw)):
raw[i] = raw[i].lower()
else:
raw = None
return raw
Expand All @@ -46,8 +48,11 @@ def zonesorter(zonefile):
if len(record) >= 5:
name = record[0]
recordtype = record[3]
for i in range(len(record) - 4):
value = value + record[i + 4] + " "
if len(record) == 5:
value = record[4]
else:
for i in range(len(record) - 4):
value = value + record[i + 4] + " "
towrite = {"name": name, "type": recordtype, "value": value}
zonedbwriter(towrite)

Expand Down Expand Up @@ -76,6 +81,7 @@ def tlddbwriter(recs):
db.v4nsamount = recs["v4resolvers"]
db.v6nsamount = recs["v6resolvers"]
db.dnssec = recs["algo"]
db.amountofkeys = recs["amountofkeys"]
db.save()


Expand All @@ -89,52 +95,45 @@ def grabber(data):
dnsseckeys = []
Arecords = 0
AAAArecords = 0
try:
ns = dns.resolver.resolve(tld, 'NS')
for server in ns:
nsservers.append(server.to_text())
except Exception as e:
print(e)
amountofkeys = 0
nses = RootZone.objects.all().filter(name=tld + ".", rectype="NS")
for ns in nses:
nsservers.append(ns.value)
for Arecord in nsservers:
try:
try:
dns.resolver.resolve(Arecord, 'A')
except Exception as e:
# retry
print(e)
dns.resolver.resolve(Arecord, 'A')
RootZone.objects.all().get(name=Arecord, rectype="A")
Arecords += 1
except Exception as e:
print(e)
except MultipleObjectsReturned:
Arecords += 1
print("Multiple IPv4 for " + Arecord)
except:
print(Arecord + " Has no IPv4 record")
for AAAArecord in nsservers:
try:
try:
dns.resolver.resolve(AAAArecord, 'AAAA')
except Exception as e:
# retry
print(e)
dns.resolver.resolve(AAAArecord, 'AAAA')
RootZone.objects.all().get(name=AAAArecord, rectype="AAAA")
AAAArecords += 1
except Exception as e:
print(e)
try:
except MultipleObjectsReturned:
AAAArecords += 1
print("Multiple IPv6 for" + AAAArecord)
except:
print(AAAArecord + " Has no IPv6 record")

dsrec = RootZone.objects.all().filter(name=tld + ".", rectype="DS")
if len(dsrec) == 0:
# Means No DNSSEC
algo = 400
else:
try:
ds = dns.resolver.resolve(tld, 'DS')
for ds in dsrec:
dnsseckeys.append(int(ds.value.split()[1]))
amountofkeys += 1
algo = max(dnsseckeys)
except Exception as e:
# retry
print(e)
ds = dns.resolver.resolve(tld, 'DS')
for dsrecord in ds:
algo = dsrecord.to_text()
line = algo.split()
dnsseckeys.append(int(line[1]))
algo = max(list(dict.fromkeys(dnsseckeys)))
except Exception as e:
algo = 400
print(e)
print(tld + " DNSSEC " + e)
algo = 300

results = {"tld": tld, "nsserveramount": int(len((nsservers))), "v4resolvers": Arecords,
"v6resolvers": AAAArecords, "algo": algo}
"v6resolvers": AAAArecords, "algo": algo, "amountkeys": amountofkeys}
tlddbwriter(results)


Expand Down

0 comments on commit 323db5f

Please sign in to comment.