Last active
August 25, 2020 10:58
-
-
Save gsdefender/383c4c51b7a87a9572bffe74c24585eb to your computer and use it in GitHub Desktop.
Create dnsmasq blocklist configuration file out of a hosts file
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
#!/usr/bin/env python | |
# For blocklists see https://github.com/blocklistproject/lists/wiki/ | |
import sys | |
with open(sys.argv[1], 'r') as blocklist_hosts_file, open(sys.argv[2], 'w+') as blocklist_dnsmasq_file: | |
for line in blocklist_hosts_file: | |
if not line.startswith('#'): | |
line = line.strip() | |
if len(line) > 0: | |
if " " in line: | |
hostline = line.split(" "); | |
host = hostline[1] | |
else: | |
host = line | |
blocklist_dnsmasq_file.write('address=/'+host+'/#') | |
blocklist_dnsmasq_file.write('\n'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment