Skip to content

Commit

Permalink
Update dnscheck command with ns records and assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
nickspaargaren committed Aug 2, 2024
1 parent 39ba6b7 commit 1eb6688
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dns-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
python-version: 3.8
- name: Install Requirements
run: pip install -r requirements.txt
- name: Check if list includes domains without dns response
- name: Check if list includes domains without no A or NS records
run: |
cd scripts
python3 dnscheck.py
35 changes: 25 additions & 10 deletions scripts/dnscheck.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import dns.resolver

import sys

def check_domain(domain):
try:
# Query for 'A' records
answers = dns.resolver.resolve(domain, "A")
# If we get any answers, the domain has a response
return bool(answers)
except dns.resolver.NXDOMAIN:
# No answer or domain does not exist or request timed out
return False
dns.resolver.resolve(domain, "A")
has_a_record = True
except (dns.resolver.NXDOMAIN, Exception):
has_a_record = False

try:
# Query for 'NS' records
dns.resolver.resolve(domain, "NS")
has_ns_record = True
except (dns.resolver.NXDOMAIN, Exception):
has_ns_record = False

return not has_a_record and not has_ns_record

def main():
found_domains = 0

with open("../pihole-google.txt") as f:
for line in f:
domain = line.strip() # strip whitespace
if domain and not domain.startswith("#"):
if not check_domain(domain):
print(f"No DNS response for domain: {domain}")

if check_domain(domain):
print(f"Domain with no A or NS records: {domain}")
found_domains += 1
if found_domains >= 10: # Exit early to reduce requests
sys.exit(1)

if found_domains > 0:
sys.exit(1)
else:
sys.exit(0)

if __name__ == "__main__":
main()

0 comments on commit 1eb6688

Please sign in to comment.