1
00:00:00,420 --> 00:00:01,680
Welcome back everybody.

2
00:00:01,680 --> 00:00:03,550
Let's continue with our ports scandal.

3
00:00:03,780 --> 00:00:09,150
So what we did by now is we important to libraries that we need in order for our program to work.

4
00:00:09,150 --> 00:00:11,810
Let's get straight into coding the main program.

5
00:00:12,480 --> 00:00:12,860
OK.

6
00:00:12,960 --> 00:00:15,050
So first thing let's think about it.

7
00:00:15,060 --> 00:00:20,210
What we need to logically do in order to discover whether airport is open or closed.

8
00:00:20,310 --> 00:00:25,980
Well we need to establish a connection with the target machine and then we need to try to connect to

9
00:00:25,980 --> 00:00:29,970
the specific port if we manage to connect the port is open.

10
00:00:30,060 --> 00:00:32,880
If we don't manage to connect the port is closed.

11
00:00:33,270 --> 00:00:37,560
Now there is not a thing that can happen and that is that the port is filtered but we're not going to

12
00:00:37,560 --> 00:00:39,380
cover that at the moment.

13
00:00:39,390 --> 00:00:43,140
So first of all let's see how we can establish the connection.

14
00:00:43,140 --> 00:00:50,310
Here is where we use this socket library socket library allows us to establish the connection over internet.

15
00:00:50,460 --> 00:00:52,200
So how can we do that.

16
00:00:52,200 --> 00:00:57,240
Well it's rather easy and it's something that people use throughout this course a lot.

17
00:00:57,240 --> 00:01:02,700
It's a same shame of a few different lines of code that will allow us to connect to the target machine.

18
00:01:03,660 --> 00:01:08,280
So in the first line we will define a socket descriptor.

19
00:01:08,280 --> 00:01:14,710
We do that by specifying the name and then equals socket that socket just like this.

20
00:01:14,710 --> 00:01:17,940
We defined the socket descriptor and you can name this anything you want.

21
00:01:17,940 --> 00:01:20,490
It doesn't have to be named socket can be named S..

22
00:01:20,790 --> 00:01:26,070
But for the purpose of this material we're going to leave it on sock as soon as we do that we can try

23
00:01:26,070 --> 00:01:34,110
to connect to the target machine so socket connect and inside of this connect function we need to specify

24
00:01:34,110 --> 00:01:41,760
to open and to close brackets and there will need to specify the IP address and the port that we want

25
00:01:41,760 --> 00:01:42,860
to connect to.

26
00:01:42,860 --> 00:01:44,060
All right.

27
00:01:44,070 --> 00:01:49,860
Now you will see right away that once again this IP address and this port is under the line threat.

28
00:01:49,950 --> 00:01:52,830
That means that this is not defined.

29
00:01:52,830 --> 00:01:58,980
So we need to define what IP addresses and what port is what we are going to do is we are simply just

30
00:01:58,980 --> 00:02:04,830
going to create a variable which would be called IP address and we're going to set this variable to

31
00:02:04,830 --> 00:02:10,610
be equal to whatever the user of this program inputs during the running of the program.

32
00:02:10,620 --> 00:02:15,450
Now what they mean by that is we are going to use the input function which allows us to add the runtime

33
00:02:15,450 --> 00:02:18,630
specified the IP address that we want to scan.

34
00:02:18,660 --> 00:02:25,520
So we're going to prompt to the user of this program something like this enter target to scan.

35
00:02:27,180 --> 00:02:28,320
OK.

36
00:02:30,840 --> 00:02:39,300
Now that we have that we also need to define the port and let's say the port will be port 80 it will

37
00:02:39,300 --> 00:02:42,270
be a simple integer so we're going to select it like this.

38
00:02:42,270 --> 00:02:48,300
And now our code is good to go all we're left to do is we are left to wrap this inside of a try and

39
00:02:48,300 --> 00:02:52,960
accept rule and destroy unacceptable acceptable basically means that we are going to try this.

40
00:02:53,010 --> 00:02:59,340
And in case that doesn't work we're going to try something else which will be under this except part

41
00:02:59,730 --> 00:03:02,400
so try and then suck it up connect.

42
00:03:02,460 --> 00:03:04,280
We are trying to connect to the port.

43
00:03:04,770 --> 00:03:10,070
And if we don't manage to connect we're going to print to the screen.

44
00:03:10,530 --> 00:03:22,380
That's the port port is closed and we can simply just specify port 80 is closed because we are scanning

45
00:03:22,380 --> 00:03:25,230
that port if we do manage to connect.

46
00:03:25,230 --> 00:03:29,280
We can print port 80 is open.

47
00:03:29,720 --> 00:03:30,060
OK.

48
00:03:30,690 --> 00:03:33,650
So this is the base part of the program.

49
00:03:33,660 --> 00:03:35,940
Let's see whether this works.

50
00:03:36,000 --> 00:03:40,770
Now in order to test this and see whether it works I'm going to pick up random IP address which in this

51
00:03:40,770 --> 00:03:43,290
case will be the IP address of my laptop.

52
00:03:43,290 --> 00:03:48,840
And in your case you can simply just scan any website on the Internet for example let's say we go to

53
00:03:48,840 --> 00:03:53,220
Firefox and we can visit any website we want.

54
00:03:53,250 --> 00:03:58,830
Now keep in mind once we actually managed to visit the website that means that the port 80 is open because

55
00:03:58,830 --> 00:04:00,080
we are loading the web page.

56
00:04:00,090 --> 00:04:02,160
So let's go to this one.

57
00:04:03,300 --> 00:04:05,730
You can choose any you like.

58
00:04:05,730 --> 00:04:07,080
I'm going to scan this one

59
00:04:09,810 --> 00:04:12,250
OK so let's copy this.

60
00:04:12,260 --> 00:04:14,670
This is the name of the website.

61
00:04:14,710 --> 00:04:19,300
Let's go right here inside of our terminal and let's try to run the program.

62
00:04:19,370 --> 00:04:31,190
Python 3 and then the name of the program which in our case is in our case it is Python 3 or scanner.

63
00:04:31,190 --> 00:04:35,480
That is why it will ask us to enter the target scan.

64
00:04:35,480 --> 00:04:37,920
Now you will notice if you specify like this.

65
00:04:38,000 --> 00:04:41,500
So we paste the name of the website and we click you enter.

66
00:04:41,500 --> 00:04:43,770
It will tell you that the port 80 is closed.

67
00:04:44,480 --> 00:04:47,720
Now why does it tell that is the port 80 really closed.

68
00:04:47,840 --> 00:04:53,570
Well not really since we actually managed to open it right here on our Firefox.

69
00:04:53,570 --> 00:04:56,230
Therefore something is wrong with our program.

70
00:04:56,300 --> 00:04:59,230
Well we cannot really specify the link to the actual Web site.

71
00:04:59,240 --> 00:05:02,140
So how can we discover the IP address to this Web site.

72
00:05:02,150 --> 00:05:04,250
Well we can use something called a..

73
00:05:04,250 --> 00:05:15,520
Look up and we specify the actual link press here enter and what this will do loops it says cannot find.

74
00:05:15,560 --> 00:05:20,420
Let's just try like this without the HDP.

75
00:05:20,480 --> 00:05:24,960
W W W and then the name of the website.

76
00:05:25,170 --> 00:05:26,500
Okay so here it is.

77
00:05:26,560 --> 00:05:31,570
Now we are able to retrieve the IP address to the specific Web site.

78
00:05:31,690 --> 00:05:34,260
What if we copy this IP address and go with this.

79
00:05:34,270 --> 00:05:42,210
So copy and let's clear the screen and run our ports can Canada once again enter target to scan.

80
00:05:42,400 --> 00:05:45,850
We face this and now we get the correct result.

81
00:05:45,850 --> 00:05:47,870
It says port 80 is open.

82
00:05:48,420 --> 00:05:48,780
OK.

83
00:05:49,090 --> 00:05:52,240
So from now on what we did we created two simple variables.

84
00:05:52,240 --> 00:05:56,890
One will host the IP address that we input during the running of the program and the other one will

85
00:05:56,890 --> 00:05:58,930
host the port number 80.

86
00:05:58,960 --> 00:06:00,320
So we are not inputting this.

87
00:06:00,320 --> 00:06:01,550
We're not changing this.

88
00:06:01,570 --> 00:06:04,480
This will simply just tick to eighty four now.

89
00:06:04,480 --> 00:06:09,610
Then we tried to connect and if we managed to connect we print at the port 80 is open.

90
00:06:09,610 --> 00:06:14,010
If we don't manage to connect we print port 80 it's closed again.

91
00:06:14,110 --> 00:06:19,220
So good for now we discovered that the port 80 is open on this specific Web site that we can't.

92
00:06:20,110 --> 00:06:21,720
But this is not really what we want.

93
00:06:21,760 --> 00:06:22,630
Right.

94
00:06:22,660 --> 00:06:24,980
We want to actually scan multiple targets.

95
00:06:25,000 --> 00:06:29,180
We want to scan all ports or as many number of forces would like.

96
00:06:29,380 --> 00:06:35,920
We want to print which port is open which port is closed and ideally we also want to connect to that

97
00:06:35,920 --> 00:06:40,150
port and see which software is it running on that open port.

98
00:06:40,360 --> 00:06:42,670
Now that port scanner would be a really good one.

99
00:06:43,480 --> 00:06:47,390
So let's see in the next few videos how we can implement all of that.

100
00:06:47,470 --> 00:06:53,170
We would also like to change this program to also accept the links and not just the IP addresses.

101
00:06:53,200 --> 00:06:58,660
So you saw previously we couldn't really specify the link it gave us the wrong result because it cannot

102
00:06:58,660 --> 00:07:04,180
really connect to a link inside of this program but we also want to make sure that once the user of

103
00:07:04,180 --> 00:07:09,880
this program specifies the links such as w w w Google dot com it will also managed to discover open

104
00:07:09,880 --> 00:07:11,290
and closed ports.

105
00:07:11,290 --> 00:07:15,990
So we're going to see how we can perform all of that in the next few lectures from now on.

106
00:07:15,990 --> 00:07:19,400
We created the base part and we are ready to continue coding on.

107
00:07:20,050 --> 00:07:20,370
All right.

108
00:07:20,380 --> 00:07:22,390
So hope I tuned in equatorial by.
