-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update dnscheck command with ns records and assertion
- Loading branch information
1 parent
39ba6b7
commit 1eb6688
Showing
2 changed files
with
26 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |