Blocks specified websites during working hours by editing the system's hosts file.
You only need one main Python file:
website_blocker.py-
Python 3.x
-
Admin/root privileges (to modify the
hostsfile)
-
Modifies the hosts file on your system.
-
Redirects websites to 127.0.0.1, essentially blocking them.
-
Unblocks them after working hours.
-
Windows:
C:\Windows\System32\drivers\etc\hosts -
Linux/Mac:
/etc/hosts
website_blocker.py-
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.
-
GUI using
tkinterorPyQt -
Add/Remove websites dynamically
-
Block based on categories (social, entertainment)
-
Notifications or logging
β Fe
-
GUI to
-
S
-
View
-
Ru
-
Run with admin/root permissions.
-
Run the script:
python website_blocker_gui.py- Add websites, and click Start Blocking.
-
Save/load blocked websites list to file
-
Customize working hours in GUI
-
Tray icon or minimize-to-tray
Auto-start on system boot
Step 1: Install PyInstaller
First, you'll need to install PyInstaller to
pip install pyinstallerStep 2: Create
-
Navigate to the directory where y
-
Run the following command to create a standalone app (this will generate a
.appfi)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
Now you have a standalone macO that runs yo
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.
MIT License Β© 2025