Skip to content

Block distracting webistes using system hosts file, plain python

License

Notifications You must be signed in to change notification settings

menzhik/hosts-page-blocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hosts-page-blocker

Python 3.6+ Ruff CI

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.

Prerequisites

  • Python 3.6 or newer (stdlib only, no dependencies)
  • Admin/root privileges (required to modify hosts file)
  • Linux, macOS, or Windows

Usage

  1. Clone the repo:
git clone https://github.com/menzhik/hosts-page-blocker.git
cd hosts-page-blocker
  1. Run with admin/root privileges:
# Linux/macOS
sudo python3 main.py

# Windows (run terminal as Administrator)
python main.py
  1. Enter URLs to block:
Number of pages: 1
Enter URL: example.com

Re-running the script is safe — it replaces the old block instead of appending duplicates.

How it works

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.

Development

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 check

License

MIT License — see LICENSE

About

Block distracting webistes using system hosts file, plain python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages