Created
August 29, 2021 13:25
-
-
Save AdriDevelopsThings/aa3fee7aed52640593737d4ec514886b to your computer and use it in GitHub Desktop.
Generates a bind9 file with blocked zone configurations.
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
# needs requests as package | |
# install with: `pip install requests` | |
BLOCK_LISTS = [ | |
{ | |
"url": "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts", | |
"type": "hosts" | |
}, | |
{ | |
"url": "https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt", | |
"type": "list" | |
}, | |
{ | |
"url": "https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt", | |
"type": "list" | |
} | |
] | |
ZONE_CONFIGURATION_FILE = "/etc/bind/zones.adblock" | |
ZONE_DB_FILE = "/etc/bind/db.adblock" | |
# Code start | |
import requests | |
domains = [] | |
for block_list in BLOCK_LISTS: | |
response = requests.get(block_list["url"]) | |
if response.status_code == 200: | |
content = [x for x in response.content.decode("utf-8").split("\n") if x and not x.startswith("#")] | |
if block_list["type"] == "hosts": | |
content = [x.split(" ")[1] for x in content] | |
domains.extend([x for x in content if x not in domains]) | |
zone_configuration = open(ZONE_CONFIGURATION_FILE, "w") | |
[zone_configuration.write("zone \"" + domain + "\" IN { type master; notify no; file \"" + ZONE_DB_FILE + "\"; };\n") for domain in domains] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment