I use this script to block too distracting websites like youtube, twitter, linkedin, mails, facebook, etc. when I'm working.
I combine it with task scheduler to automatically block the websites at a certain time and unblock them at another time.
This is a simple Powershell script to add or remove a list of hostnames and ip's from your hosts file.
The host file is used to map hostnames to ip addresses. This is useful when you want to block websites or redirect them.
The host file is located in the following location:
C:\Windows\System32\drivers\etc\hosts
- Powershell
- Administrator privileges (updating the hosts file requires admin privileges)
The script can be used in the following way:
./updateHosts.ps1 add <filename>
./updateHosts.ps1 remove <filename>
./updateHosts.ps1 show
It has to be a text file in the same format as the hosts file:
ip hostname
127.0.0.1 youtube.com
127.0.0.1 linkedin.com
127.0.0.1 twitter.com
...
./updateHosts.ps1 add hosts.txt
./updateHosts.ps1 remove hosts.txt
./updateHosts.ps1 show
Inspire by: https://gist.github.com/markembling/173887