File size: 1,711 Bytes
8dcc7a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import os
import time
import datetime
import psutil
blacklisted_apps = [
"Telegram.exe",
"Discord.exe",
"vlc.exe",
"WinStore.App.exe"
]
blocked_sites = [
"youtube.com",
"www.youtube.com",
"t.me",
"web.telegram.org",
"chat.openai.com",
"chatgpt.com",
"huggingface.co",
"github.com",
"chat.qwen.ai",
"chat.deepseek.com",
"civitai.com",
"https://chat.deepseek.com/"
]
hosts_path = r"C:\Windows\System32\drivers\etc\hosts"
redirect_ip = "127.0.0.1"
log_file = "blocked_log.txt"
CHECK_INTERVAL = 10
def log_event(event):
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(log_file, "a", encoding="utf-8") as f:
f.write(f"[{now}] {event}\n")
def block_websites():
with open(hosts_path, "r+", encoding="utf-8") as file:
content = file.read()
for site in blocked_sites:
entry = f"{redirect_ip} {site}"
if entry not in content:
file.write(entry + "\n")
log_event(f"Blocked site: {site}")
print("✅ All websites blocked.")
def close_apps():
for proc in psutil.process_iter(["pid", "name"]):
try:
if proc.info["name"] in blacklisted_apps:
os.system(f"taskkill /F /PID {proc.info['pid']}")
print(f"â›” Closed app: {proc.info['name']}")
log_event(f"Closed app: {proc.info['name']}")
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue
print("🚀 Anti-Distraction System Active...")
block_websites()
while True:
close_apps()
time.sleep(CHECK_INTERVAL)
|