1
00:00:00,300 --> 00:00:01,460
Welcome back everyone.

2
00:00:01,470 --> 00:00:05,020
And this is the last video to our port scandal project.

3
00:00:05,280 --> 00:00:11,940
Right now what we're going to do is we are going to first of all recap what we did inside of this program.

4
00:00:11,940 --> 00:00:15,870
So we're just going to go through the program code real fast and explain what everything is doing.

5
00:00:15,870 --> 00:00:22,180
Once again and then I will show you how you can use this program and imported inside of another program

6
00:00:22,220 --> 00:00:23,800
so you can use it.

7
00:00:23,810 --> 00:00:24,170
All right.

8
00:00:24,170 --> 00:00:29,150
So first of all let us navigate all the way down to the beginning of the program here.

9
00:00:29,150 --> 00:00:33,250
As you can see we prompt the user to input a target or multiple targets.

10
00:00:33,270 --> 00:00:37,040
We then check whether they specified one target or multiple targets.

11
00:00:37,100 --> 00:00:42,020
If we find comma inside of this variable that means they specified multiple targets.

12
00:00:42,020 --> 00:00:44,540
Therefore we will split all of those targets.

13
00:00:44,540 --> 00:00:50,780
And for each and every IP address inside of this variable we will perform the scanning of that IP address

14
00:00:52,010 --> 00:00:52,940
in any other case.

15
00:00:52,940 --> 00:00:57,200
That means if we didn't find comma that means they only specified one target.

16
00:00:57,200 --> 00:01:03,530
Therefore we are going to perform this scan function onto the targets variable as it is only storing

17
00:01:03,650 --> 00:01:06,130
one IP address or one domain name.

18
00:01:06,190 --> 00:01:07,200
Okay.

19
00:01:07,640 --> 00:01:14,270
Then once we navigate to this can function here we first take the converted IP variable and then we

20
00:01:14,270 --> 00:01:20,650
perform the check IP function onto the specified target if the specified target is simply IP address.

21
00:01:20,720 --> 00:01:26,810
We will return that IP address and it will be stored inside of the converted IP in case the target is

22
00:01:26,810 --> 00:01:28,390
an actual domain name.

23
00:01:28,400 --> 00:01:33,680
Therefore we're going to perform this socket get called by name method which allows us to convert the

24
00:01:33,680 --> 00:01:35,810
domain name into an IP address.

25
00:01:36,590 --> 00:01:37,880
OK.

26
00:01:38,150 --> 00:01:43,160
Right after we convert the IP address we scan for 100 ports.

27
00:01:43,160 --> 00:01:48,700
Now this number keep in mind can be changed for example you can scan for first 500 ports if you'd like.

28
00:01:48,710 --> 00:01:50,430
It doesn't have to be 100.

29
00:01:50,450 --> 00:01:52,890
This is a number that you can change.

30
00:01:52,910 --> 00:01:57,530
Now another thing that you might want to implement in this program if you want is you can also prompted

31
00:01:57,530 --> 00:02:00,770
the user for how many ports they want to scan.

32
00:02:01,130 --> 00:02:06,010
How we will do that but we will simply do that by specifying something like this.

33
00:02:06,110 --> 00:02:10,450
You go to the beginning of the program and there you can simply type port number.

34
00:02:11,180 --> 00:02:14,690
Let's say we call the variable like that and then input

35
00:02:18,220 --> 00:02:28,890
enter number of ports that you want to scan then the user would enter the number of ports.

36
00:02:29,050 --> 00:02:32,570
Let's not leave these two to be capital.

37
00:02:32,620 --> 00:02:33,910
Let's leave it like this.

38
00:02:33,910 --> 00:02:36,430
So enter number of ports that you want to scan.

39
00:02:36,430 --> 00:02:42,870
Then you would take the sexual variable and you will also paste it into the scan function once you do

40
00:02:42,870 --> 00:02:43,270
that.

41
00:02:43,290 --> 00:02:51,740
If you go back to the scan function right here you would simply have something like Port num as a parameter

42
00:02:52,170 --> 00:02:55,860
and then you would have four port in range one through port now.

43
00:02:56,100 --> 00:03:02,940
So it wouldn't have five hundred you would have something like port not so simple as that but we're

44
00:03:02,940 --> 00:03:04,290
not going to leave it like this.

45
00:03:04,290 --> 00:03:06,960
Let's just leave it as the way it was before.

46
00:03:07,590 --> 00:03:12,210
This is just something that you can implement and leave it in the program if you want.

47
00:03:12,210 --> 00:03:17,880
In this case we are not going to use that since it is not necessary we simply just always want to scan

48
00:03:18,210 --> 00:03:22,010
for first 500 ports so we'll delete this

49
00:03:24,780 --> 00:03:30,240
also keep in mind if you leave that option you also need to specify the port number inside of this line

50
00:03:30,240 --> 00:03:35,700
right here and also inside of this line right here as a second parameter to the function.

51
00:03:35,740 --> 00:03:36,080
OK.

52
00:03:36,630 --> 00:03:42,060
So once we get to this for loop we scan for each and every port between the range of 1 and 500.

53
00:03:42,210 --> 00:03:45,370
And we do that by using the scan port function.

54
00:03:45,540 --> 00:03:49,470
So let's go to the scan function and this is the main part of the program.

55
00:03:49,500 --> 00:03:51,120
Here we create the socket object.

56
00:03:51,150 --> 00:03:56,520
We set the timeout so we don't actually waste too much of our time trying to figure out whether a port

57
00:03:56,520 --> 00:03:57,870
is closed the open.

58
00:03:57,870 --> 00:04:03,890
Keep in mind that the accuracy of the scan will depend on the amount of the timer that you set.

59
00:04:03,900 --> 00:04:08,970
The lower the timeout the lesser the accuracy the higher the timeout the bigger the accuracy.

60
00:04:09,570 --> 00:04:09,950
OK.

61
00:04:09,960 --> 00:04:16,350
So then we perform the Connect function onto the target IP address and the port number right after it.

62
00:04:16,380 --> 00:04:22,110
If we manage to connect we will simply just try to get banner and figure out which software is the target

63
00:04:22,110 --> 00:04:27,420
running on that specific open port if we don't manage to get the vendor will simply just print open

64
00:04:27,420 --> 00:04:28,830
port without the banner.

65
00:04:28,830 --> 00:04:34,560
And if we do manage to get it will print open port then the port number and we will attach the banner

66
00:04:34,920 --> 00:04:36,450
right after the two dots.

67
00:04:37,090 --> 00:04:38,220
Okay.

68
00:04:38,280 --> 00:04:43,290
In any other case if we don't manage to connect we will simply just pass and not print anything because

69
00:04:43,290 --> 00:04:46,670
we are not really interested in printing which ports are closed.

70
00:04:46,710 --> 00:04:49,820
We're only interested in printing the open ports.

71
00:04:49,850 --> 00:04:50,180
Okay.

72
00:04:50,280 --> 00:04:55,980
So this is basically the whole idea of this port scanner project and now let's see how we can actually

73
00:04:55,980 --> 00:04:59,810
use this program and imported into another program.

74
00:04:59,820 --> 00:05:00,110
Okay.

75
00:05:00,150 --> 00:05:01,590
So how can we do that.

76
00:05:01,590 --> 00:05:05,100
Well first of all what we need to do is we need to create another file.

77
00:05:05,160 --> 00:05:08,280
So I'm just going to go right click on the port scanner

78
00:05:11,360 --> 00:05:16,680
then go to the new and then python file and let's call this file IP eyepiece.

79
00:05:16,720 --> 00:05:24,650
Can be white it will automatically added right here so you will have two taps one for the port scanner

80
00:05:24,680 --> 00:05:26,420
and one for the IP scan.

81
00:05:26,480 --> 00:05:29,010
And now we want to import this program.

82
00:05:29,030 --> 00:05:33,470
Now one thing before you actually do that is you need to make sure that both of these files are in the

83
00:05:33,470 --> 00:05:34,720
same directory.

84
00:05:34,760 --> 00:05:37,710
In my case they are both in the port scanner project.

85
00:05:37,760 --> 00:05:41,100
Therefore they are in the same directory so I can proceed.

86
00:05:41,510 --> 00:05:45,670
Now the next thing that we need to take a look at is the name of our port scanner.

87
00:05:45,710 --> 00:05:48,350
So it is named port scanner dot P Y.

88
00:05:48,350 --> 00:05:53,360
Now in order to actually import this file into another file in the same directory we simply just type

89
00:05:53,450 --> 00:05:57,560
the command import and then the name of the program that we want to import.

90
00:05:57,590 --> 00:06:04,520
In our case it is port scanner so Let's type it right here for the scanner and you will see that by

91
00:06:04,520 --> 00:06:06,470
charm already recognizes it.

92
00:06:06,500 --> 00:06:12,080
Therefore we successfully managed to import our port scanner program.

93
00:06:12,240 --> 00:06:20,600
Now how can we perform the same task that we did right here just without typing all of this code well

94
00:06:20,660 --> 00:06:27,120
we can simply just call these functions from our second program and use them independently.

95
00:06:27,140 --> 00:06:27,500
Okay.

96
00:06:27,650 --> 00:06:33,910
So the use of this importing is basically if anyone else wants to use our port scanner they can see

97
00:06:33,970 --> 00:06:39,290
we just imported and use the functions from that program into their own program.

98
00:06:39,290 --> 00:06:47,310
So what we going to specify right here first is the IP address to for example B S BHP that Vaughn Webb

99
00:06:47,870 --> 00:06:49,400
dot com.

100
00:06:49,400 --> 00:06:53,000
This is the domain name that we used to test with our port scanner before.

101
00:06:53,300 --> 00:06:54,770
So nothing new right here.

102
00:06:55,010 --> 00:07:00,500
And all we need to do to actually run this port scanner inside of a different program is to call the

103
00:07:00,500 --> 00:07:02,880
scan function.

104
00:07:03,110 --> 00:07:06,960
Now at first you might be asking well why recalling the scan function.

105
00:07:07,010 --> 00:07:12,740
Well basically you will notice that by calling this can function all of the other functions get called

106
00:07:12,830 --> 00:07:13,910
as well.

107
00:07:14,090 --> 00:07:20,510
For example inside with the scan function we first called the check IP function in order to check for

108
00:07:20,510 --> 00:07:21,680
the IP address.

109
00:07:21,680 --> 00:07:27,370
Then we call this can port function which will scan each and every port that we specify inside of these

110
00:07:27,380 --> 00:07:33,560
for loop and inside of the scan port function they get better function gets called in order to print

111
00:07:33,650 --> 00:07:34,520
the banner.

112
00:07:34,520 --> 00:07:37,150
So we didn't need to call specifically all of these functions.

113
00:07:37,160 --> 00:07:40,740
We can simply just call the scan function.

114
00:07:40,900 --> 00:07:41,270
OK.

115
00:07:41,400 --> 00:07:42,690
So how can we do that.

116
00:07:42,720 --> 00:07:47,520
Well in order to call a function from a different program we first of all need to specify the program

117
00:07:47,550 --> 00:07:52,530
name just the same way that you specify a method from a different library for example.

118
00:07:52,650 --> 00:08:00,420
Right here we use socket library and we called a method or a function and we call the function from

119
00:08:00,420 --> 00:08:01,810
that specific library.

120
00:08:01,860 --> 00:08:08,010
But before we had to specify the library name same way goes here we first need to specify ports candor

121
00:08:08,220 --> 00:08:15,160
and then dot and then scan you'll remember that these can function takes one argument which will be

122
00:08:15,160 --> 00:08:23,190
the target as the PI charm already tells us right here and now our target will be the IP address and

123
00:08:23,280 --> 00:08:24,050
believe it or not.

124
00:08:24,060 --> 00:08:30,630
But this is the entire program just by using these three lines we can perform the same thing that we

125
00:08:30,630 --> 00:08:32,360
did inside of all reports.

126
00:08:32,370 --> 00:08:35,310
Can project.

127
00:08:35,320 --> 00:08:37,810
So this is the power of importing libraries.

128
00:08:37,840 --> 00:08:42,760
You can see that anyone who wants to use this can simply just write three lines and they will perform

129
00:08:42,760 --> 00:08:49,030
the same task that we performed by coding the entire port scanner but there is another thing that we

130
00:08:49,030 --> 00:08:52,440
need to take a look at before we actually try to run the IP scan.

131
00:08:52,810 --> 00:08:55,540
You might notice this part right here.

132
00:08:55,630 --> 00:08:58,470
Well we don't really want to run this since.

133
00:08:58,600 --> 00:09:04,450
First of all we're calling this can function already inside of our IP scan program.

134
00:09:04,480 --> 00:09:10,810
Therefore we don't really want to call it twice and we would actually call it because by importing the

135
00:09:10,810 --> 00:09:18,430
ports Canada into our IP scan we're also calling this part of the code importing a library simply means

136
00:09:18,430 --> 00:09:23,650
that we are going to paste the entire port scanner code into our IP scan function.

137
00:09:23,650 --> 00:09:27,120
Therefore this part of the code will also get red.

138
00:09:27,340 --> 00:09:30,970
So how can we make sure that this part of the code doesn't get red.

139
00:09:30,970 --> 00:09:41,460
Well simply we can type if underscore underscore name underscore underscore equals equals and then open

140
00:09:41,490 --> 00:09:49,920
double quotes underscore underscore may underscore underscore if this is equal to Maine then we're going

141
00:09:49,920 --> 00:09:58,750
to run this part of code so let's tap all of these lines in so they belong to this if statement and

142
00:09:58,750 --> 00:10:03,510
now this part of program will only get friend if we run the port scanner.

143
00:10:05,050 --> 00:10:11,170
This line basically means that the actual python will recognize whether this program is being ran as

144
00:10:11,170 --> 00:10:16,690
a main program or it is being imported into a different program and ran from there.

145
00:10:16,690 --> 00:10:22,880
In case it is being important a different program like in this case right here then it will not run.

146
00:10:22,930 --> 00:10:28,660
This part of the code if it is not imported into a different program and if we simply just tried to

147
00:10:28,660 --> 00:10:33,400
run the port scanner itself then this part of the code will actually run.

148
00:10:33,400 --> 00:10:36,990
And that is the meaning of this line right here.

149
00:10:37,020 --> 00:10:42,250
You can simply just remember this as if this is the main program then run this part of the code.

150
00:10:42,280 --> 00:10:42,650
OK.

151
00:10:42,780 --> 00:10:45,600
So right now let's test our IP scandal.

152
00:10:45,660 --> 00:10:54,930
Why let's open the terminal and let's type Python 3 IP scan that be why.

153
00:10:55,960 --> 00:10:57,900
You can see it is scanning the target.

154
00:10:58,060 --> 00:11:04,310
It already found the two ports open and it will scan for first 500 ports as we specified and change

155
00:11:04,310 --> 00:11:06,890
it in number from 100 to 500.

156
00:11:06,910 --> 00:11:10,550
You can see we are also getting some banners from these open ports.

157
00:11:10,570 --> 00:11:16,440
We got open port 106 open port one hundred ten one hundred and forty three.

158
00:11:16,540 --> 00:11:19,050
We can see here is a long banner from that port.

159
00:11:19,060 --> 00:11:20,730
Not really sure what this is.

160
00:11:21,850 --> 00:11:27,040
We also discover another open port which is port four hundred and sixty five and therefore our program

161
00:11:27,040 --> 00:11:29,710
closes as it reached the 500 ports number.

162
00:11:30,370 --> 00:11:32,030
Okay so it actually does work.

163
00:11:32,080 --> 00:11:37,360
Now another thing that you should keep in mind is that you will need to actually code this part of the

164
00:11:37,360 --> 00:11:44,890
code into this IP scan because for example if a user specifies comma and then an IP address this will

165
00:11:44,890 --> 00:11:48,190
not work because we do not have this part.

166
00:11:48,190 --> 00:11:49,900
And this if statement right here.

167
00:11:50,470 --> 00:11:55,360
Therefore it will not be able to scan because of this comma right here.

168
00:11:55,360 --> 00:12:01,060
So if you want to be able to scan multiple targets from your IP scan program make sure that you implement

169
00:12:01,120 --> 00:12:04,550
this if statement into the IP scan.

170
00:12:04,900 --> 00:12:07,000
But we are not going to do that at the moment.

171
00:12:07,000 --> 00:12:08,020
There is no need for that.

172
00:12:08,020 --> 00:12:12,540
We already did that in the port scanner program and I will leave that up to you.

173
00:12:12,650 --> 00:12:12,990
Okay.

174
00:12:13,090 --> 00:12:19,390
So with this we actually finish our first project which will be the port scanner and in the next project

175
00:12:19,420 --> 00:12:24,700
We're going to take a look at how we can create the vulnerability scanner which will be based on this

176
00:12:24,700 --> 00:12:26,650
port scandal that we just created.

177
00:12:26,680 --> 00:12:30,330
So make sure not to delete this program as we are going to need it.

178
00:12:30,370 --> 00:12:36,150
You also know that you will have all of these actual programs in the resources at the end of each project.

179
00:12:36,200 --> 00:12:36,510
Okay.

180
00:12:36,550 --> 00:12:40,380
So you can simply just download them if you don't want to code.

181
00:12:40,510 --> 00:12:45,630
I hope you enjoyed this lecture and I will see you in the vulnerability scanner project.

182
00:12:45,630 --> 00:12:46,150
Take care.

183
00:12:46,150 --> 00:12:46,720
And by.
