Skip to content

Commit

Permalink
Add dns check to domains (#189)
Browse files Browse the repository at this point in the history
* Add dns check to domains

* Remove resolvers that shouldn't be honored

* Add dnspython to requirements

* Update script with NoAnswer and Timeout

* Add dnscheck command

* Remove NoAnswer and Timeout from dns response exceptions

* Update dnscheck command with ns records and assertion

* Remove looking for A records

* TEMP Remove early exit

* Update Github Action name

* Automate removing domains without ns records

* Add check for changes to automate removing domains without ns records

* Remove failure

* Update automate removing domains without ns records

* Update automate removing domains without ns records name

* Update automate removing domains without ns records

* Remove domains without NS records

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
nickspaargaren and github-actions[bot] committed Aug 6, 2024
1 parent 93337bd commit f951a0a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/dns-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: DNS
on: [push]
jobs:
dns-check:
name: Remove domains without NS records
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
name: Python setup
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install Requirements
run: pip install -r requirements.txt
- name: Check if list includes domains without NS records
run: |
cd scripts
python3 dnscheck.py
- name: Check for changes
id: check_changes
run: |
if [[ `git status --porcelain pihole-google.txt` ]]; then
echo "Domains found without NS records"
echo "::set-output name=changes_detected::true"
else
echo "No domains without NS records found"
echo "::set-output name=changes_detected::false"
fi
- name: Commit updated pihole-google.txt
if: steps.check_changes.outputs.changes_detected == 'true'
run: |
git add pihole-google.txt
git commit -am "Remove domains without NS records"
git push
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ do-install-packages:
@. .venv/bin/activate; pip install -r requirements.txt

whois: ## Check all domains with whois
@. .venv/bin/activate; cd scripts && python domain-check-api.py
@. .venv/bin/activate; cd scripts && python domain-check-api.py

dnscheck: ## Check all domains if they have a response
@. .venv/bin/activate; cd scripts && python dnscheck.py
2 changes: 1 addition & 1 deletion pihole-google.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8773,4 +8773,4 @@ www.tofu.jibemobile.com
www.tokyo.jibemobile.com
www.viper.jibemobile.com
www.watermelon.jibemobile.com
yellowstone.jibemobile.com
yellowstone.jibemobile.com
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python-whois==0.9.4
python-whois==0.9.4
dnspython==2.6.1
36 changes: 36 additions & 0 deletions scripts/dnscheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import dns.resolver

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

return not has_ns_record

def main():
found_domains = 0
domains_with_ns_records = []

with open("../pihole-google.txt") as f:
for line in f:
domain = line.strip() # strip whitespace
if domain and not domain.startswith("#"):
if check_domain(domain):
print(f"Domain without NS records: {domain}")
found_domains += 1
else:
domains_with_ns_records.append(line)
else:
domains_with_ns_records.append(line)

# Write remaining domains back to the file
with open("../pihole-google.txt", "w") as f:
f.writelines(domains_with_ns_records)

if __name__ == "__main__":
main()

0 comments on commit f951a0a

Please sign in to comment.