1
00:00:00,900 --> 00:00:05,050
So how do we go about blocking websites with Python?

2
00:00:05,520 --> 00:00:08,720
Windows, MAC or Linux

3
00:00:08,720 --> 00:00:16,000
they have a host file which is something like this.

4
00:00:16,200 --> 00:00:17,580
So this is the host file.

5
00:00:17,880 --> 00:00:21,120
And if you open the host file

6
00:00:25,050 --> 00:00:27,220
you'll see some lines there.

7
00:00:27,690 --> 00:00:35,100
And what this host file is for is that if you want to block certain web sites such as Facebook

8
00:00:35,610 --> 00:00:38,130
or this mail live here

9
00:00:38,430 --> 00:00:43,060
what you do is you tag them here as I have done here.

10
00:00:43,500 --> 00:00:45,210
I've typed them via Python

11
00:00:45,240 --> 00:00:46,190
in this case.

12
00:00:46,560 --> 00:00:48,400
But you can also type them manually

13
00:00:48,400 --> 00:00:54,000
in that case you don't  have control of the times when you want them to be here.

14
00:00:54,540 --> 00:00:57,240
So if you have a look at this, this is saying that

15
00:01:00,000 --> 00:01:05,640
the IP address should be placed in the first column followed by the corresponding hostname which means

16
00:01:06,060 --> 00:01:09,190
this is a redirect IP address.

17
00:01:09,250 --> 00:01:17,300
And this is a host name which underlies that if you want to block Facebook you want to redirect the browser

18
00:01:17,700 --> 00:01:25,620
to this IP address which is the local IP address of your computer which means when you try to access

19
00:01:25,620 --> 00:01:26,430
Facebook

20
00:01:28,980 --> 00:01:34,220
you'll be redirected to that IP that shows this error web page.

21
00:01:34,220 --> 00:01:35,000
Good.

22
00:01:35,300 --> 00:01:38,160
Now this hosts file

23
00:01:38,220 --> 00:01:44,700
on Windows it is located in this directory here.

24
00:01:45,840 --> 00:01:48,650
So Windows system 32 drivers.

25
00:01:48,780 --> 00:01:55,170
And then you have the host file which doesn't have an extension but you can open it as a text file

26
00:01:55,220 --> 00:01:55,330

27
00:01:55,390 --> 00:02:04,050
in Atom or other text editors. On Linux or Mac that host file path would be something like

28
00:02:06,930 --> 00:02:07,480
this and host.

29
00:02:07,530 --> 00:02:11,100
So, very straight forward.

30
00:02:11,130 --> 00:02:16,210
This is both for Linux and Mac and on Windows

31
00:02:16,290 --> 00:02:18,980
that was this one here.

32
00:02:19,010 --> 00:02:26,040
So I'll copy that and just put it here.

33
00:02:27,660 --> 00:02:31,270
So that's for MAC and Linux and Windows.

34
00:02:31,930 --> 00:02:32,700
Good.

35
00:02:33,060 --> 00:02:36,720
Now that we know how this host file works

36
00:02:36,720 --> 00:02:38,820
we can open that as a file via Python

37
00:02:38,910 --> 00:02:47,260
using file handling methods and we can add lines of text at certain times of the day and

38
00:02:47,280 --> 00:02:54,200
this host file. For instance let's say I work between 8 a.m. and 4 p.m..

39
00:02:54,570 --> 00:03:00,660
In that case I'll write a Python script that runs the entire day and checks every let's say every

40
00:03:00,660 --> 00:03:02,880
five minutes it checks the time.

41
00:03:02,880 --> 00:03:08,750
And if it's past 4:00 p.m. then it will delete these two lines.

42
00:03:08,910 --> 00:03:15,080
But if you are between 08:00 and 16:00 Python on will add these two lines in this host file 

43
00:03:15,180 --> 00:03:15,830
and the host file

44
00:03:16,380 --> 00:03:23,220
will block access to these two websites. So that is starting to make sense I believe and all we need to start

45
00:03:23,220 --> 00:03:30,250
off is you have to think about let's say two websites that you want a block or more or just one.

46
00:03:30,330 --> 00:03:35,120
And also figure out where your host is located which I already showed to you.

47
00:03:35,340 --> 00:03:41,250
And yeah we should be good to go to start writing the program and we'll do that in the next lecture.

48
00:03:41,260 --> 00:03:41,680

