A Go utility to block and unblock websites by modifying the hosts file on Windows, Linux, and macOS.
-
Clone the Repository
git clone https://github.com/ni5arga/website-blocker cd website-blocker go mod download -
Build the Executable
go build -o blocker.exe blocker.go
This will create the
blocker.exeexecutables.
-
Create
sites.txtList the websites to block or unblock, one per line:
www.example.com example.com instagram.com -
Edit Time Limits
Modify the
startBlockandendBlockvariables inblocker.goto set your desired blocking times:var ( startBlock = "09:00" // Blocking start time endBlock = "17:00" // Blocking end time )
-
Adjust Host Path (if needed)
The path to the
hostsfile is set automatically based on your operating system. Change it inblocker.goif necessary.
Run the blocker with:
sudo go run blocker.go- Blocked:
Blocked <website> - Unblocked:
Unblocked <website> - Errors:
Error: <message>
MIT License. See LICENSE for details.