Skip to main content

A CLI tool to temporarily block websites by modifying the hosts file

Project description

StopWeb

Block websites permanently to help you stay focused. Works by editing your system's hosts file. You can also set a temporary duration if needed.

I built this because I kept getting distracted by social media and news sites when trying to work. Simple solution: block them until you decide to unblock.

What it does

  • Blocks websites until you manually unblock them
  • Works on Mac, Linux, and Windows
  • Lets you see what's currently blocked
  • Can unblock sites early if needed

Install

pip install stopweb

Basic usage

Block Facebook permanently:

sudo stopweb facebook.com

Block multiple sites at once:

sudo stopweb facebook.com youtube.com reddit.com

See what's blocked:

sudo stopweb --list

Unblock a site:

sudo stopweb --remove facebook.com

Remove all blocks:

sudo stopweb --clear

Temporarily block a site (expires automatically):

sudo stopweb -d 2h twitter.com      # 2 hours
sudo stopweb --duration 1d reddit.com  # 1 day

How it works

StopWeb edits your hosts file to redirect blocked sites to localhost (127.0.0.1).

On Mac/Linux that's /etc/hosts, on Windows it's C:\Windows\System32\drivers\etc\hosts.

It adds lines like:

127.0.0.1    facebook.com    # StopWeb:
# For temporary blocks, an expiry is recorded, e.g.
127.0.0.1    twitter.com     # StopWeb: expires=2025-01-01T12:00:00

Blocked sites stay blocked until you run the remove or clear command.

Notes

  • Requires sudo/admin privileges (needs to edit system files)
  • You might need to clear your browser cache after blocking/unblocking
  • Creates a backup of your hosts file before making changes
  • If something goes wrong, your original hosts file is saved as hosts.stopweb_backup
  • Temporary blocks are removed automatically by running stopweb --cleanup

Notifications (manual edits)

StopWeb can alert you if someone edits your hosts file and removes or changes StopWeb entries by hand. It does not notify on additions.

  • Default recipient: linj1@tcd.ie
  • Snapshot is checked whenever you run a StopWeb command; if differences are found since the last run, an email is sent (or a file is saved in ~/.config/stopweb/outbox/ if SMTP isn't configured).
  • To configure SMTP, edit ~/.config/stopweb/stopweb.json and set settings.notifications.smtp fields.

What triggers a notification:

  • StopWeb line removed from hosts (e.g., someone deleted # StopWeb: lines)
  • StopWeb line modified (e.g., IP or expires metadata changed)

What does not trigger a notification:

  • Adding new StopWeb entries
  • Normal StopWeb commands you run yourself (block/remove/clear/cleanup)

Audit and Watch

Single-run audit:

sudo stopweb --audit

Continuous watch (poll every 15 seconds):

sudo stopweb --watch --interval 15

Tip: for testing without touching your real hosts file, set an override:

export STOPWEB_HOSTS_PATH="/tmp/stopweb-hosts"

Then put some lines into that file and run stopweb --audit or --watch.

Why not just use browser extensions?

Browser extensions can be easily disabled when you're feeling weak. Editing the hosts file is more permanent - you'd have to remember the exact command to undo it.

Plus this works system-wide, not just in your browser.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stopweb-0.1.2.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stopweb-0.1.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file stopweb-0.1.2.tar.gz.

File metadata

  • Download URL: stopweb-0.1.2.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for stopweb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c4ef0feb7d93c442749e098bf30c4cd8df97187170ec341a621db7cfd4127e82
MD5 b337be7fdfc4d42e737af303298505b5
BLAKE2b-256 c87e3f2039cd0ddbb47c17d29b94c6be27c462e3493eecee6484a12a9826b27a

See more details on using hashes here.

File details

Details for the file stopweb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: stopweb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for stopweb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 17881cb007a789829900ece950047770bcc36f79a4e5932b2a0b662b60f2a26b
MD5 822363228f17055eec343f7956594262
BLAKE2b-256 424172bb5ea87a28b6192701d2f39f09616c8be38b763b80f9a5171b57aa8254

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page