Skip to content

mscbuild/web_blocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ Project: Python Website Blocker

πŸ“Œ What It Does

Blocks specified websites during working hours by editing the system's hosts file.

πŸ“ Files and Structure

You only need one main Python file:

website_blocker.py

🧰 Requirements

  • Python 3.x

  • Admin/root privileges (to modify the hosts file)

🧠 How It Works

  • Modifies the hosts file on your system.

  • Redirects websites to 127.0.0.1, essentially blocking them.

  • Unblocks them after working hours.

βš™οΈ Location of hosts File

  • Windows: C:\Windows\System32\drivers\etc\hosts

  • Linux/Mac: /etc/hosts

🧾 Sample Code

website_blocker.py

⚠️ Note

  • Run as Admin/root: You’ll need to run the script with administrative privileges.

  • Schedule It: Use Task Scheduler (Windows) or cron (Linux/macOS) to run it in the background.

βœ… Possible Upgrades

  • GUI using tkinter or PyQt

  • Add/Remove websites dynamically

  • Block based on categories (social, entertainment)

  • Notifications or logging

🎨 Python Website Blocker with GUI (tkinter)

βœ… Fe

  • GUI to

  • S

  • View

  • Ru

πŸ“ File: website_blocker_gui.py

βš™οΈ How to Run

  • Run with admin/root permissions.

  • Run the script:

python website_blocker_gui.py
  • Add websites, and click Start Blocking.

🧠 Optional Enhancements

  • Save/load blocked websites list to file

  • Customize working hours in GUI

  • Tray icon or minimize-to-tray

Auto-start on system boot

πŸ› οΈ Steps to Convert to a macOS App

Step 1: Install PyInstaller

First, you'll need to install PyInstaller to

pip install pyinstaller

Step 2: Create

  • Navigate to the directory where y

  • Run the following command to create a standalone app (this will generate a .app fi)

    pyinstaller --onefile --windowed website_blocker_gui.py
  • --onefile: Pa

  • --windowed: Preve

This will generate a dist folder cwebsite_blocker_.

Step 3:

Once PyInstaller finishes, you should see a .app file in the `dist directoryWebsite GUI jus

Step 4:

  • If yo

  • Creat (if you)

  • Open Keychain A andDevelo certi

  • Use t

    codesign --sign "Developer ID Application: Your Name (Team ID)" path/to/website_blocker_gui.app

    Step 5:

If you want to create a downloadable disk image for distribution, you can package the .app file .dmg file for

  • Install create-dmg:
npm install -g create-dmg
  • Run th
create-dmg "dist/website_blocker_gui.app" "dist/website_blocker_gui.dmg"

This will generate a .dmg file, w

πŸŽ‰ Y

Now you have a standalone macO that runs yo

Notifications

Note

If you use an app-level blocker, make sure it is protected from abuse..

Tip

Blocking websites may not always be effective, and users can bypass blocking. It is just one tool for increasing security and control.

Important

A real application would require more complex mechanisms for processing requests, filtering, storing a list of blocked sites, etc.

Warning

Warning: Site blockers may conflict with other network and browser settings. Please note potential issues and possible alternative solutions.

πŸ“œ License

MIT License Β© 2025

Releases

No releases published

Packages

No packages published

Languages