Last active
July 10, 2024 09:05
-
-
Save anilshanbhag/33e8fadbe3860f36010de34d9570708c to your computer and use it in GitHub Desktop.
Script to block/unblock websites using /etc/hosts
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/python | |
""" | |
Greatest productivity script ever created. Adds whole bunch of entries to /etc/hosts | |
Need to manually delete it !:/ | |
""" | |
import sys | |
lines = open('/etc/hosts').readlines() | |
lines = [line.strip() for line in lines] | |
domains = ['facebook.com', 'instagram.com', | |
'news.ycombinator.com', 'twitter.com', 'wsj.com', 'seekingalpha.com', | |
'reddit.com', 'snapchat.com', 'youtube.com', | |
'finance.yahoo.com', 'livemint.com', 'hindustantimes.com', 'cnbc.com', | |
'linkedin.com', 'robinhood.com', 'nytimes.com', 'twitch.tv', 'bloomberg.com', | |
'moneycontrol.com', 'scmp.com', 'asia.nikkei.com'] | |
print("Blocking sites") | |
block = ['127.0.0.1 ' + domain for domain in domains] + ['127.0.0.1 www.' + domain for domain in domains] | |
open('/etc/hosts', 'a').write('\n'.join(block)) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@wagmachado , does it actually works for family for current version?, it doesn't work for me.