Block distracting websites at the OS level via /etc/hosts.
Harder to bypass than browser extensions (requires OS-level file editing)
Target use-case: Block distracting websites (e.g. social media, news, messaging) during focused work hours.
- Python 3.6 or newer (stdlib only, no dependencies)
- Admin/root privileges (required to modify hosts file)
- Linux, macOS, or Windows
- Clone the repo:
git clone https://github.com/menzhik/hosts-page-blocker.git
cd hosts-page-blocker- Run with admin/root privileges:
# Linux/macOS
sudo python3 main.py
# Windows (run terminal as Administrator)
python main.py- Enter URLs to block:
Number of pages: 1
Enter URL: example.comRe-running the script is safe — it replaces the old block instead of appending duplicates.
The tool adds entries to your system's hosts file between markers:
# hosts-page-blocker BEGIN
0.0.0.0 example.com
::1 example.com
0.0.0.0 www.example.com
::1 www.example.com
# hosts-page-blocker END
Examples use placeholder domains (example.com). Replace them locally with the domains you want to block.
For contributors (optional, not required for users):
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dev dependencies
uv sync
# Run linter
uv run ruff checkMIT License — see LICENSE