-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite_blocker.py
More file actions
59 lines (50 loc) · 2.3 KB
/
website_blocker.py
File metadata and controls
59 lines (50 loc) · 2.3 KB
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
#importing required liberary
from tkinter import *
#creating a window
window = Tk()
window.geometry('650x400')
window.minsize(650,400)
window.maxsize(650,400)
window.title(" DataFlair Website Blocker")
heading=Label(window, text ='Website Blocker' , font ='arial')
heading.pack()
host_path ='C:\Windows\System32\drivers\etc\hosts'
ip_address = '127.0.0.1'
label1=Label(window, text ='Enter Website :' , font ='arial 13 bold')
label1.place(x=5 ,y=60)
enter_Website = Text(window,font = 'arial',height='2', width = '40')
enter_Website.place(x= 140,y = 60)
def Blocker():
website_lists = enter_Website.get(1.0,END)
Website = list(website_lists.split(","))
with open (host_path , 'r+') as host_file:
file_content = host_file.read()
for web in Website:
if web in file_content:
display=Label(window, text = 'Already Blocked' , font = 'arial')
display.place(x=200,y=200)
pass
else:
host_file.write(ip_address + " " + web + '\n')
Label(window, text = "Blocked", font = 'arial').place(x=230,y =200)
def Unblock():
website_lists = enter_Website.get(1.0,END)
Website = list(website_lists.split(","))
with open (host_path , 'r+') as host_file:
file_content = host_file.readlines()
for web in Website:
if web in website_lists:
with open (host_path , 'r+') as f:
for line in file_content:
if line.strip(',') != website_lists:
f.write(line)
Label(window, text = "UnBlocked", font = 'arial').place(x=350,y =200)
pass
else:
display=Label(window, text = 'Already UnBlocked' , font = 'arial')
display.place(x=350,y=200)
block_button = Button(window, text = 'Block',font = 'arial',pady = 5,command = Blocker ,width = 6, bg = 'royal blue1', activebackground = 'grey')
block_button.place(x = 230, y = 150)
unblock_button = Button(window, text = 'UnBlock',font = 'arial',pady = 5,command = Unblock ,width = 6, bg = 'royal blue1', activebackground = 'grey')
unblock_button.place(x = 350, y = 150)
window.mainloop()