You are on page 1of 13

COMPUTER SCIENCE

PROJECT

NAME : V. Sivaraman
GRADE : 12th
DIVISION : Everest
SCHOOL : EVA World School
CERTIFICATE

This is to certify that Sivaraman Vasudevan


of Grade 12 has successfully completed the
project work entitled “WEBSITE BLOCKER
USING PYTHON” during the academic year
2022-23 in the partial fulfilment of the practical
examination for the Computer Science
conducted by CBSE.

____________________. ____________________. ____________________.

External Examiner. Principal. Internal Examiner.

School Seal:
ACKNOWLEDGEMENT

I wish to express my deep gratitude and sincere


thanks Dr. Anita Agarwal, principal of Eva
World School for her encouragement and for all
the facilities that she provided us.

I would also like to express my special thanks of


gratitude to my C.S teacher Mrs. Sunita Sabat
without whose help this project would not be
possible and had also provided all the help needed
for the completion of this project.

I am also grateful to my parents and classmates


who helped me during this project with their
constructive criticism and advice.

Sivaraman Vasudevan
Grade 12 Everest
INDEX
Sr. No. Topic/Title Pg. No

1 Introduction 1

2 Steps to build 2
Website blocker
3 Procedure 3

4 Modules and 5
Functions
5 Source code 7

6 Outputs 8

7 Bibliography 9
INTRODUCTION

Website Blocker is a tool that denies access to websites


permanently or by schedule. To use the internet safely we
can block all websites from unwanted categories.
The objective of Website Blocker python project is to block
the given websites from any device. This project will help
the user to stay away from their distraction by blocking
websites from their device so that they cannot open them.
In this Python Website Blocker Project, the user can enter
multiple websites to block, and then clicking on the block
button will check the condition that if the website already
blocked then print ‘already blocked’ else blocked all that
websites and print ‘blocked’.
To implement website blocker project, we will use the
basic concepts of Python and Tkinter library.
Tkinter is a standard GUI Python library. It is one of the
fastest and easiest ways to build GUI applications.
Steps to build a website
blocker using python

• Installing the library


• Importing the module
• Creating the display window
• Creating an entry widget
• Defining “Block” function
• Creating the block button
PROCEDURE

• Installing the Library:


To install the library, you can use pip install command to
the command prompt.

pip install tkinter

• Importing the module:


We import modules from tkinter library.
from tkinter import *

• Creating the display window:


We use tkinter library to create a window where we’ll
enter the components of our GUI.
root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("Sivaraman - Website Blocker")
Label(root, text ='WEBSITE BLOCKER' , font ='arial 20 bold').pack()
Label(root, text ='Sivaraman Project' , font ='arial 20
bold').pack(side=BOTTOM)
• Creating an entry widget:
Storing the path to our host file and the IP address used
by the localhost in there respective variables. Creating a
text box to enter the link of the website we want to
block.
host_path ='C:\Windows\System32\drivers\etc\hosts'
ip_address = '127.0.0.1'

Label(root, text ='Enter Website :' , font ='arial 13 bold').place(x=5 ,y=60)


Websites = Text(root,font = 'arial 10',height='2', width = '40', wrap = WORD,
padx=5, pady=5)
Websites.place(x= 140,y = 60)

• Defining the “Block” function:


This function will get all websites entered by the user
and split contents with the comma and convert them
into a list and store it into Website variable. If the
website is already in file_content variable then print a
label with text “already Blocked”. Else it will block all
the given website and print label of text “Blocked”.
def Blocker():
website_lists = Websites.get(1.0,END)
Website = list(website_lists.split(","))
with open (host_path , 'r+') as host_file:
file_content = host_file.read()
for website in Website:
if website in file_content:
Label(root, text = 'Already Blocked' , font = 'arial 12
bold').place(x=200,y=200)
pass
else:
host_file.write(ip_address + " " + website + '\n')
Label(root, text = "Blocked", font = 'arial 12
bold').place(x=230,y =200)
• Creating the block button:
When we click on the Block button it will call the
Blocker function.
block = Button(root, text = 'Block',font = 'arial 12 bold',pady = 5,command =
Blocker ,width = 6, bg = 'royal blue1', activebackground = 'sky blue')
block.place(x = 230, y = 150)
root.mainloop()

Modules and Functions


Modules Used:
• Tkinter module belongs to a standard library of GUI in
Python. It helps us to create a dialog box with any
information that we want to provide or get from the
users.

Functions Used:
• Blocker(): It takes the input and converts it into a list.
It then blocks all the websites in the list from the host
file.
• main(): This function is the main function of the
program where the above-mentioned functions are
called for the program to work.
Variables Used:
• root : Name which we refer to our window
• host_path : Stores the path of our host file
• ip_address : Stores the IP address used by localhost
• Websites : Stores websites entered by user
• website_lists : Get all the website to enter by the user
• Website : Creates a list of website_lists
• host_file : Control variable for the host_path file
• file_content : Reads and stores the host_file contents
• website : Control variable for the loop
• block : Used to display button on our window
SOURCE CODE
from tkinter import *
root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("Sivaraman - Website Blocker")
Label(root, text ='WEBSITE BLOCKER' , font ='arial 20 bold').pack()
Label(root, text ='Sivaraman Project' , font ='arial 20
bold').pack(side=BOTTOM)
host_path ='C:\Windows\System32\drivers\etc\hosts'
ip_address = '127.0.0.1'

Label(root, text ='Enter Website :' , font ='arial 13 bold').place(x=5 ,y=60)


Websites = Text(root,font = 'arial 10',height='2', width = '40', wrap = WORD,
padx=5, pady=5)
Websites.place(x= 140,y = 60)
def Blocker():
website_lists = Websites.get(1.0,END)
Website = list(website_lists.split(","))
with open (host_path , 'r+') as host_file:
file_content = host_file.read()
for website in Website:
if website in file_content:
Label(root, text = 'Already Blocked' , font = 'arial 12
bold').place(x=200,y=200)
pass
else:
host_file.write(ip_address + " " + website + '\n')
Label(root, text = "Blocked", font = 'arial 12
bold').place(x=230,y =200)

block = Button(root, text = 'Block',font = 'arial 12 bold',pady = 5,command =


Blocker ,width = 6, bg = 'royal blue1', activebackground = 'sky blue')
block.place(x = 230, y = 150)
root.mainloop()

To download,click here:

WebBlocker.py
OUTPUTS
BIBLIOGRAPHY

• techvidvan.com
• geeksforgeeks.org
• Computer science Class 12 by Sumita
Arora Publications
• askpython.com
• youtube.com

You might also like