Block Unwanted Hosts is an open-source tool written in Go designed to block unwanted websites by updating the system's hosts file. It fetches a list of blocked websites from various sources and appends them to the hosts file, effectively preventing access to these sites.
More info: https://en.wikipedia.org/wiki/Shock_site
- Fetches and blocks websites from predefined sources.
- Appends entries to the hosts file -
/etc/hosts. - Clears the DNS cache to apply changes immediately.
To block unwanted hosts, import the github.com/feruzoripov/block-unwanted-hosts/internal/app/blocking package in your Go code and call blocking.FetchAndBlockWebsites().
package main
import (
"log"
"github.com/feruzoripov/block-unwanted-hosts/internal/app/blocking"
)
func main() {
err := blocking.FetchAndBlockWebsites()
if err != nil {
log.Fatal("Error: ", err)
}
}Note: Ensure that you have the necessary permissions to update the hosts file, and you may need to run the tool with administrative privileges (sudo).
Goinstalledgitinstalled
-
Clone the repository:
git clone https://github.com/feruzoripov/block-unwanted-hosts.git cd block-unwanted-hosts/cmd -
Build:
go build -o blocking
-
Run (requires
sudofor updating/etc/hostsand clearing DNS cache):sudo ./blocking
Block Unwanted Hosts is designed to run on the following operating systems:
- macOS
- Debian-based Linux (e.g., Ubuntu)
Please note that these are the currently supported operating systems. While it may work on other Linux distributions, the tool has been tested and optimized for macOS and Debian-based systems.
If you encounter any issues on a different operating system, feel free to submit an issue or contribute to improve compatibility.
This project is licensed under the MIT License. See the LICENSE file for details.