Skip to content

Instantly share code, notes, and snippets.

@gsdefender
Last active August 25, 2020 10:58
Show Gist options
  • Save gsdefender/383c4c51b7a87a9572bffe74c24585eb to your computer and use it in GitHub Desktop.
Save gsdefender/383c4c51b7a87a9572bffe74c24585eb to your computer and use it in GitHub Desktop.
Create dnsmasq blocklist configuration file out of a hosts file
#!/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