Skip to content

Instantly share code, notes, and snippets.

@ggdx
Created March 28, 2021 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ggdx/b237ffe6b21333f8e9363458ca7632b7 to your computer and use it in GitHub Desktop.
Save ggdx/b237ffe6b21333f8e9363458ca7632b7 to your computer and use it in GitHub Desktop.
Adds a huge list of domains to block to /etc/hosts
import os
""" site_block.txt - https://gist.github.com/ggdx/e333c291312c90a6c5f35d5b06fd9632
This script takes a while, could most likely be made more efficient but
does the job in prevent my kids from accessing things they shouldn't
as well as largely stops tracking scripts embedded in websites.
"""
path = './site_block.txt'
def read_large_file(file_handler):
for line in file_handler:
yield line
with open(path) as file_handler:
for url in read_large_file(file_handler):
os.system(f'echo "127.0.0.1 {url}" >> /etc/hosts')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment