DEV Community

Discussion on: How to build website blocker in Python

Collapse
 
vampiire profile image
Vamp • Edited

neat article thanks for sharing. an alternative approach is to create a hosts.blocked file. then use a cron job (or python) to simply swap the files:

create two files:
hosts.original (copy of original etc hosts)
hosts.blocked (original + deadend for blocked sites)

(on)
copy hosts.blocked to etc hosts

(off)
copy hosts.original to etc hosts

this will ensure you are not mutating the original file. you can then convert your tool to generate the .blocked file based on that list of sites (auto appending common prefixes like www)