0% found this document useful (0 votes)
62 views31 pages

Atul Summer Internship Report

The document describes building a website blocker application using Python. It discusses objectives like blocking distracting websites during work hours. It provides details on the project implementation, including using the host file to map website URLs to localhost, and scheduling the script to automatically run during specified times. Code snippets are included to demonstrate configuring the host file mappings and scheduling the script.

Uploaded by

Adarsh Upadhayay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views31 pages

Atul Summer Internship Report

The document describes building a website blocker application using Python. It discusses objectives like blocking distracting websites during work hours. It provides details on the project implementation, including using the host file to map website URLs to localhost, and scheduling the script to automatically run during specified times. Code snippets are included to demonstrate configuring the host file mappings and scheduling the script.

Uploaded by

Adarsh Upadhayay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Atul pratap singh tomar 1814310057

SUMMER TRAINING REPORT

WEBSITE BLOCKER USING PYTHON


Submitted in partial fulfillment of the
Requirements for the award of
Degree of Bachelor of Technology in Computer Science Engineering

Name: Atul pratap singh tomar


University Roll No. 1814310057

SUBMITTED TO: Ms. Pushpanjali

Department of Computer Science & Engineering


IMS ENGINEERING COLLEGE
GHAZIABAD (UP).
Atul pratap singh tomar 1814310057

CERTIFICATE
Atul pratap singh tomar 1814310057

DECLARATION

I hereby declare that the Summer Training Report entitled WEBSITE BLOCKER USING
PYHTON is an authentic record of my own work as requirements of Summer Training during
the period from MAY 2020 to JUNE 2020 for the award of degree of B.Tech. (Computer
Science & Engineering), IMS ENGINEERING COLLEGE, GZB.

(Signature of student)
Atul pratap singh tomar
1814310057
Date: 17-03-2020

Head of Department
(Signature and Seal)
Atul pratap singh tomar 1814310057

ACKNOWLEDGEMENT

I have taken efforts in this project. However, it would not have


been possible without the kind support and help of many
individuals and organizations. I would like to extend my sincere
thanks to all of them.
I am highly indebted to EDULYT INDIA for their guidance and
constant supervision as well as for providing necessary
information regarding the project & also for their support in
completing the project.
I would like to express my gratitude towards my parents &
member of team for their kind co-operation and
encouragement which help me in completion of this project.
I would like to express my special gratitude and thanks to
industry persons for giving me such attention and time.
My thanks and appreciations also go to my colleague in
developing the project and people who have willingly helped
me out with their abilities.
Atul pratap singh tomar 1814310057

About Institute :

Edulyt India is a India's leading Education Management firm in


the field of ANALYTICS, operating in INDIA and UNITED STATES.
Their core area of working is in Machine Learning with Python
for Banking and Finance domain. Their team is working on
leading Artificial Intelligence tools to make the world a better
easier place to live. They are highly skilled and trained in
delivering training to Aspiring Graduates. Founded in 2015 with
a Mission to Train Fresh Graduates with MINIMAL COST. Team
of 40+ Data Scientists working in Banking, Healthcare,
Consulting & Auditing, Automobile and IT sectors with
renowned MNC’s in INDIA and UNITED STATES.
Atul pratap singh tomar 1814310057

Their Associations :
1. 50+ colleges are collaborated with us.
2. Successfully placed 800+ students.
3. Transformed life's of 1500+ students by career counselling in
getting jobs.
4. 40+ MNC’s are collaborated with us.
5. 80+ consultancies are associated with us.
Atul pratap singh tomar 1814310057

CONTENT
⮚ Abstract
⮚ Introduction
o Objective
o Project Description
o Project Implementation
o Process
o The hosts file
o Configuration
⮚ Benefits of Website Blocker
⮚ Prerequisite
⮚ What is python
⮚ What is Host File
o Working of host file
o Location of hosts file
⮚ Scheduling
o Scheduling in Windows
o Scheduling in Mac
⮚ Source Code
⮚ Snapshots
⮚ References
Atul pratap singh tomar 1814310057

Abstract

We are going to build a real-time most popular python


application known as website blocker.
This application can be used to block the websites so that the
user can not open them during the specific period.
Let's discuss how can we build such an application by using
python. This python project is very simple to understand &
build and best for a developer for practising purposes. This kind
of project will help the user to block certain distracting,
unwanted websites from your PC like Gaming websites,
Facebook, Instagram, Youtube, or any kind of website that
bothers you, during your work hours or study hour, so that the
user can not open them during the specific period. Rather than
using other party applications to block certain websites, we can
create our very own customized application which will block
websites of our choice and developing a website blocker in
python is not so difficult too as I mentioned earlier.
Atul pratap singh tomar 1814310057

Introduction
we are going to build a real-time most popular python
application known as website blocker.This application can be
used to block the websites so that the user can not open them
during the specific period.

Let's discuss how can we build such an application by using

python.

Objective:
The objective of Python website blocker is to block some
certain websites which can distract the user during the
specified amount of time.
In this, we will block the access to the working time in this
python application is considered from 9 AM to 5 PM. The time
period except that time will be considered as free time.
The list of some particular websites during the working hours so
that the user can only access those websites during the free
time only.

Project Description:
Atul pratap singh tomar 1814310057

So, let begin with a description of the project what we doing in


the project and programming language, etc.

1. In this project, we will build a python based project, which


will assist the user with blocking a specific site, like
Instagram, Facebook, Youtube, etc. and so on for a specific
time of the time like 9:00 to 10:00 hours. We are going to
utilize the python worked in libraries, so no compelling
reason to introduce some other bundles.

2. Python-For programming reason, we are going to utilize


Python as the Programming language. Python is easy to learn
and work on with the language. It is an elevated level,
broadly useful programming and exceptionally intruded on
language.

3. Some fundamental information on the host document since


we are going to list sites which we need to block. Every
operating system has a hosts file. The location of the host file
may be different for the different operating systems. This
host file is a map hostname to the IP address of the machine.
Right now, we are going to list websites which we want to
block.

Project Implementation:
1. We know that every system/PC has a host file whether it is
Mac, Windows or Linux and write commands to get a host file.
Atul pratap singh tomar 1814310057

2. Now we should focus on  Working of host file-  Host is an


operating system file that maps hostnames to IP addresses. We
will outline/mapping hostnames of websites to our localhost
address. Utilizing python file handling manipulation we need to
compose the hostname in hosts.txt and evacuate all lines after
your working hours. In this host file, we are going to list
websites which we want to block.
3. Now do the coding part and write the script.
4. Now it's time to schedule the above script in Windows/Mac/
Linux.
5. Here I am going to tell scheduling the script in the window
since it is somewhat dubious, let start -

● Most importantly change the expansion of your script


from ".py" to ".pyw".
● Now open task scheduler and click on “Create Task” and
fill the name of your decision and flag Run with the most
elevated benefit.
● Now go to triggers, select "At startup" to start the task.
● Go to the Action bar and make another activity and give
the way/path of your script.
● Go to the conditions bar and unflag the power section.
● Press ok and your script is scheduled.
● Script scheduled is complete now.

6. Finally, restart your computer and see the result.


Atul pratap singh tomar 1814310057

Process:
To block the access to a specific website on the computer, we
need to configure the hosts file.
The hosts file:
The hosts file is a local file which was used to map hostnames
to IP addresses in the old days. Although the DNS service is
used nowadays to map the hostnames to the IP addresses, the
host file is still very complex and can be used to configure the
mapping of the IP addresses locally.
Location of hosts file:
The location of the hosts file varies from operating system to
operating system.
Windows: C:\Windows\System32\drivers\etc
mac and Linux: /etc/hosts

Configuration:
Since the hosts file contains the mapping between the host
names and IP addresses, let's look at the content of our hosts
file first stored as /etc/hosts as we use CentOS 7 (Linux).
Atul pratap singh tomar 1814310057

As we can see in the above image, the mappings are saved for
the localhost with the IP address 127.0.0.1.

Similarly, we can redirect any hostname back to the localhost IP


(127.0.0.1). It will block the access to that hostname and
redirect that to localhost on each request.

For testimony, let's edit the content of hosts file and add some
of the following lines to it. To make changes to
the /etc/hosts file, we will need to change its permissions.

Run the following command on the terminal to change the


permissions.

$ sudo chmod 777 /etc/hosts  

1. 127.0.0.1       www.facebook.com   
Atul pratap singh tomar 1814310057

Save the file and try to open the www.facebook.com


using the browser.
Atul pratap singh tomar 1814310057

Benefits of Website Blocker:

1. It can prevent Internet users visiting websites harboring


malware or ransomware, websites that are known to be
fake and used for phishing attacks
2. In a business environment, a web blocker can also prevent
employees from visiting time-wasting websites unrelated
to work.
Atul pratap singh tomar 1814310057

3. Benefit of a web blocker to prevent Internet users openly


viewing inappropriate content.

Prerequisite:
● Python 3.x installed
● Basic knowledge of Python
● Host file

What is python:
Atul pratap singh tomar 1814310057

Python is an interpreted, object-oriented, high-level


programming language with dynamic semantics. Its high-level
built in data structures, combined with dynamic typing and
dynamic binding, make it very attractive for Rapid Application
Development, as well as for use as a scripting or glue language
to connect existing components together. Python's simple, easy
to learn syntax emphasizes readability and therefore reduces
the cost of program maintenance. Python supports modules
and packages, which encourages program modularity and code
reuse. The Python interpreter and the extensive standard
library are available in source or binary form without charge for
all major platforms, and can be freely distributed.
Often, programmers fall in love with Python because of the
increased productivity it provides. Since there is no compilation
step, the edit-test-debug cycle is incredibly fast. Debugging
Python programs is easy: a bug or bad input will never cause a
segmentation fault. Instead, when the interpreter discovers an
error, it raises an exception. When the program doesn't catch
the exception, the interpreter prints a stack trace. A source
level debugger allows inspection of local and global variables,
evaluation of arbitrary expressions, setting breakpoints,
stepping through the code a line at a time, and so on. The
debugger is written in Python itself, testifying to Python's
introspective power. On the other hand, often the quickest way
to debug a program is to add a few print statements to the
Atul pratap singh tomar 1814310057

source: the fast edit-test-debug cycle makes this simple


approach very effective.

What is Host File:


The hosts file is a local file which was used to map hostnames
to IP addresses in the old days. Although the DNS service is
used nowadays to map the hostnames to the IP addresses, the
host file is still very complex and can be used to configure the
mapping of the IP addresses locally.

Working of host file: 


Host is an operating system file which maps hostnames to IP
addresses. In this program we will be mapping hostnames of
websites to our localhost address. Using python file handling
manipulation we will write the hostname in hosts.txt and
remove the lines after your working hours.

Location of hosts file:


The location of the hosts file varies from operating system to
operating system.
Windows: C:\Windows\System32 \drivers\etc
mac and Linux: /etc/hosts
Atul pratap singh tomar 1814310057

Scheduling:

Scheduling in Windows: 
Scheduling of above script is little bit trick but I will guide you
step by step-
1. First of all change the extension of your script from “.py” to
“.pyw”.
Atul pratap singh tomar 1814310057

2. Now open task scheduler. Task scheduler should look like


this

You may see website blocker already scheduled because I have


already scheduled in my computer for my testing purpose.
Follow further instruction of scheduling carefully in order to
schedule website blocker in your computer.
Atul pratap singh tomar 1814310057

3. Click on “create task”. Fill the name of your choice and flag
“Run with highest privilege”.
Atul pratap singh tomar 1814310057

4. Now go to triggers, select “At startup” for begin the task

4. Go to Action bar and create a new action and give path of


your script.
Atul pratap singh tomar 1814310057
Atul pratap singh tomar 1814310057

6. Go to conditions bar and unflag the power section


Atul pratap singh tomar 1814310057

7. Press ok and you can see the script scheduled.


Atul pratap singh tomar 1814310057

8. Finally restart your computer.

Scheduling in Mac:

1. Write following command in terminal:


sudo crontab -e
 
Your terminal should look like this:
Atul pratap singh tomar 1814310057

2. Now press “i” to go into insert/editing mode and write


@reboot python_script_path .
3. Save the tab by pressing first esc to quit write mode and
fall back to command mode and now write “:wq” and
finally press enter to validate.
4. Restart your system.
Atul pratap singh tomar 1814310057

Source code
# Run this script as root

import time
from datetime import datetime as dt

# change hosts path according to your OS


hosts_path = "/etc/hosts"
# localhost's IP
redirect = "127.0.0.1"

# websites That you want to block


website_list =
["www.facebook.com","facebook.com",
"dub119.mail.live.com","www.dub119.mail.live.com
",
"www.gmail.com","gmail.com"]

while True:

# time of your work


if dt(dt.now().year, dt.now().month, dt.now().day,8)
< dt.now() < dt(dt.now().year, dt.now().month,
dt.now().day,16):
print("Working hours...")
Atul pratap singh tomar 1814310057

with open(hosts_path, 'r+') as file:


content = file.read()
for website in website_list:
if website in content:
pass
else:
# mapping hostnames to your
localhost IP address
file.write(redirect + " " + website + "\n")
else:
with open(hosts_path, 'r+') as file:
content=file.readlines()
file.seek(0)
for line in content:
if not any(website in line for website in
website_list):
file.write(line)

# removing hostnmes from host file


file.truncate()

print("Fun hours...")
time.sleep(5)
Atul pratap singh tomar 1814310057

SNAPSHOTS

Now if we try to open – youtube.com or facebook.com, we’ll


get −
Atul pratap singh tomar 1814310057

REFERENCES

1. www.google.com
2. www.wikipedia.org
3. geeksforgeeks.org
4. python.org
5. hackerrank.com
6. w3schools.com

You might also like