1
00:00:00,480 --> 00:00:01,720
Welcome back everybody.

2
00:00:01,720 --> 00:00:03,710
And let's continue with our ports.

3
00:00:03,990 --> 00:00:08,840
So we managed to create a function that will convert the domain name into an IP address.

4
00:00:08,880 --> 00:00:12,810
And now we want to be able to specify multiple targets for our program to scan.

5
00:00:13,920 --> 00:00:14,320
OK.

6
00:00:14,400 --> 00:00:15,960
So how we can do that.

7
00:00:16,070 --> 00:00:17,650
Well it is rather easy.

8
00:00:17,670 --> 00:00:21,540
We're going to implement a little bit of changes down here at the bottom of our program.

9
00:00:22,080 --> 00:00:26,860
So here you will notice that we have the variable called IP address.

10
00:00:26,880 --> 00:00:33,360
Now it says enter target to scan but we could simply just do something like this and specify to the

11
00:00:33,360 --> 00:00:40,370
user of this program that they can also enter multiple targets by typing target slash s.

12
00:00:40,740 --> 00:00:51,280
And also we're going to specify to the user split multiple targets with a comma.

13
00:00:52,350 --> 00:00:52,730
OK.

14
00:00:52,920 --> 00:00:55,580
So simple as that.

15
00:00:55,770 --> 00:00:57,510
That does make this a little bit better.

16
00:00:57,930 --> 00:01:02,440
But this is just the part where we prompt the user how they can specify multiple targets.

17
00:01:02,440 --> 00:01:06,750
Now we need to actually split these targets and scan each one of them one by one.

18
00:01:07,620 --> 00:01:09,460
So how can we do that.

19
00:01:09,480 --> 00:01:14,830
Well first thing we're going to do is so we don't get confused we are going to rename this into the

20
00:01:14,940 --> 00:01:19,530
target's variable and then what we are going to do.

21
00:01:19,630 --> 00:01:22,800
We're going to delete this line for now.

22
00:01:22,970 --> 00:01:32,070
We're going to specify if and then comma in targets if there is common targets.

23
00:01:32,070 --> 00:01:37,820
Logically that means that the user of this program specified multiple targets can if there is not a

24
00:01:37,820 --> 00:01:43,440
comma inside of the target variable that means that the user only specified one target to scan.

25
00:01:43,470 --> 00:01:45,860
So we're going to lead by that logic.

26
00:01:45,960 --> 00:01:54,300
So if a comma is in targets then for IP address and we're going to call it simply just IP underscore

27
00:01:54,500 --> 00:02:00,970
add in targets and we're going to call the function called split.

28
00:02:01,350 --> 00:02:07,680
And what this function does is basically people split the string with the character that we specify

29
00:02:07,680 --> 00:02:09,070
inside of the brackets.

30
00:02:09,090 --> 00:02:13,050
So we want to split at every comma if we split it every common.

31
00:02:13,050 --> 00:02:16,830
That means we are going to split all of the IP addresses one by one.

32
00:02:16,830 --> 00:02:21,590
Therefore we specify right here for IP address in Target's split.

33
00:02:21,630 --> 00:02:34,530
We want to scan each and every IP address so can port IP address and then so we want to scan each and

34
00:02:34,530 --> 00:02:36,150
every target from this list.

35
00:02:36,150 --> 00:02:42,650
And in order to do that we're going to create a function which is going to be called scan.

36
00:02:42,690 --> 00:02:49,080
Now I know we do have a scan port function but we're going to use this function in order scan one single

37
00:02:49,080 --> 00:02:55,410
port one by one and we're going to call this can function in order to scan each and every target and

38
00:02:55,440 --> 00:02:59,550
also convert that domain name into an IP address if needed.

39
00:02:59,550 --> 00:03:06,450
So all that this function will take as a parameter will be the IP address which will get from this for

40
00:03:06,450 --> 00:03:07,490
loop right here.

41
00:03:08,100 --> 00:03:08,460
OK.

42
00:03:08,970 --> 00:03:15,930
We also want to strip it from any unnecessary empty spaces in case there are some.

43
00:03:15,960 --> 00:03:18,850
And right now all we need to do is code this function.

44
00:03:18,900 --> 00:03:20,220
Let's go all the way up

45
00:03:23,040 --> 00:03:26,170
and call this can function onto the target.

46
00:03:26,490 --> 00:03:29,580
So this would be one single target.

47
00:03:29,580 --> 00:03:34,380
And first we need to do is to get back the line that we lead to before which is the conversion of the

48
00:03:34,410 --> 00:03:44,710
IP address so converted underscore IP we'll be equal to check IP which is our function that we call

49
00:03:44,710 --> 00:03:51,510
that in the previous lecture and we need to check the IP address from the target which is our parameter

50
00:03:51,660 --> 00:03:52,620
inside of the function.

51
00:03:53,820 --> 00:03:54,240
OK.

52
00:03:54,990 --> 00:03:57,960
And now we will print just so we know what we are doing.

53
00:03:57,990 --> 00:04:10,080
We're going to print first of all new line character which is backslash and plus and let's make some

54
00:04:10,080 --> 00:04:13,680
type of a smiley right here which will look something like this.

55
00:04:13,680 --> 00:04:20,500
So and let's print scanning target.

56
00:04:20,580 --> 00:04:26,460
We also want to specify which target are scanning in case there are multiple ones so will specify the

57
00:04:26,460 --> 00:04:32,000
string of the target which will be either the domain name or the IP address.

58
00:04:32,280 --> 00:04:39,630
If we specify plus the string of the converted IP it'll only specify the IP address since it will already

59
00:04:39,630 --> 00:04:42,180
be converted from the domain name.

60
00:04:42,660 --> 00:04:43,680
But we don't want that.

61
00:04:43,680 --> 00:04:48,510
We want to specify plus the string of target which will be the names that the user specified to the

62
00:04:48,510 --> 00:04:49,560
program.

63
00:04:49,560 --> 00:04:59,740
And then we need to copy this part from below which is for port in range scan each and every port let's

64
00:04:59,740 --> 00:05:00,710
copy this.

65
00:05:00,730 --> 00:05:01,830
We no longer needed freight.

66
00:05:01,840 --> 00:05:09,880
Here we can delete it from here and we can move it inside of others can function.

67
00:05:09,880 --> 00:05:13,690
So right here let me just tab this properly.

68
00:05:13,690 --> 00:05:16,470
Then we are going to change a few things.

69
00:05:16,540 --> 00:05:23,560
If we need so for port in range seventy 75 to eighty five we can change that right away for example

70
00:05:23,590 --> 00:05:32,320
from Port 1 to port 100 and you can keep this number as low or as high as you want just for the purposes

71
00:05:32,320 --> 00:05:36,210
of this material we're going to leave it on on this can in 100 ports.

72
00:05:36,310 --> 00:05:41,710
Since most of the ports that we want to see whether they're open or closed will be in the first 100

73
00:05:41,710 --> 00:05:42,820
ports OK.

74
00:05:43,870 --> 00:05:49,990
And then we'll go cold this can port function on to the port number and also on to the converted IP

75
00:05:50,230 --> 00:05:53,870
which we converted in the first line of our function.

76
00:05:53,880 --> 00:05:54,230
OK.

77
00:05:54,280 --> 00:05:56,620
So everything makes sense now.

78
00:05:56,680 --> 00:06:03,040
Another thing that we need to change down here since we specified if comma in targets.

79
00:06:03,040 --> 00:06:06,870
That means that the actual user specified multiple targets to scan.

80
00:06:06,940 --> 00:06:09,950
But what if they specify only one target.

81
00:06:09,970 --> 00:06:16,630
Well then nothing of this will get executed and will not release can any target throughout our program.

82
00:06:16,630 --> 00:06:20,740
It will simply just exit the program without scanning the target.

83
00:06:20,740 --> 00:06:24,050
So we need to add an else statement right here.

84
00:06:24,220 --> 00:06:25,420
So if comment.

85
00:06:25,420 --> 00:06:26,260
Targets.

86
00:06:26,320 --> 00:06:30,770
Else we want to scan the targets.

87
00:06:30,790 --> 00:06:31,750
Simple as that.

88
00:06:31,750 --> 00:06:38,470
Because in this case the targets will be just one IP address or one domain name that it will jump from

89
00:06:38,470 --> 00:06:44,710
that function to the scan function which will convert that IP address and it will perform this can function

90
00:06:44,980 --> 00:06:50,020
onto the first 100 ports OK so everything makes sense.

91
00:06:50,030 --> 00:06:56,200
Now let's see whether we have an error inside of our program or if everything worked perfectly.

92
00:06:56,420 --> 00:06:57,680
So let's see what we can write.

93
00:06:57,680 --> 00:07:06,640
Let's open up our terminal and navigate and first novel and launch this so we can see everything and

94
00:07:06,650 --> 00:07:09,310
we need to navigate to our pie chart directory.

95
00:07:09,410 --> 00:07:11,880
It will usually be in the slash route to rectory.

96
00:07:11,900 --> 00:07:12,650
So here it is.

97
00:07:12,650 --> 00:07:20,180
By turn projects I will see to that directory type L S we have the test directory which we created once

98
00:07:20,180 --> 00:07:25,740
we install the PI term and we have our ports can of directory or our ports kind of project.

99
00:07:25,760 --> 00:07:28,370
So let's change the directory to the ports Kennard type.

100
00:07:28,360 --> 00:07:31,390
Ellis once again and here is our ports Canada.

101
00:07:31,560 --> 00:07:39,620
Why have a clear the screen and I will run the program first of all let's try it with one target.

102
00:07:39,860 --> 00:07:42,860
So let's switch it up a little bit.

103
00:07:42,910 --> 00:07:47,720
I will use my actual router IP address in order to perform test of this program.

104
00:07:47,890 --> 00:07:50,150
So I will type quantity to that 168.

105
00:07:50,170 --> 00:07:51,260
That one that one.

106
00:07:51,810 --> 00:07:56,930
Press your enter and you will see it will perform this can really fast cause my master is close to me.

107
00:07:57,130 --> 00:08:00,820
Therefore we can see most of the ports are closed.

108
00:08:00,820 --> 00:08:05,330
We have the port twenty two open 423 open.

109
00:08:06,040 --> 00:08:14,080
Let's see which ones are also open port fifty three open for the DNS and port 80 open all the other

110
00:08:14,170 --> 00:08:15,770
ports are closed.

111
00:08:17,120 --> 00:08:22,460
So right away we can notice that this is not really that good to look at.

112
00:08:22,490 --> 00:08:26,660
We didn't really want to print the close port as there is too much happening right here especially if

113
00:08:26,660 --> 00:08:28,310
you scan more than 100 ports.

114
00:08:28,310 --> 00:08:30,890
It would be really hard to find all of the open ones.

115
00:08:30,950 --> 00:08:35,870
So let's see what we can do inside of our program in order to print only the open ports.

116
00:08:35,900 --> 00:08:36,260
OK.

117
00:08:36,440 --> 00:08:44,660
So right here we need to go right here inside our code and intercept port function is our print statements

118
00:08:44,660 --> 00:08:47,090
for the port open and port closed.

119
00:08:47,090 --> 00:08:52,190
So what we can do is instead of printing port is closed we can delete this

120
00:08:57,710 --> 00:09:00,540
and we can simply specify parts.

121
00:09:00,560 --> 00:09:05,230
Now what this will do is it will not perform anything it will not print any statement.

122
00:09:05,330 --> 00:09:09,130
It will simply just pass in case the port is closed.

123
00:09:09,140 --> 00:09:09,890
OK.

124
00:09:09,920 --> 00:09:10,910
Simple as that.

125
00:09:11,270 --> 00:09:12,740
Let's test it once again.

126
00:09:12,740 --> 00:09:20,090
Python 3 port scanner that v y specify the IP address on my rather once again.

127
00:09:20,090 --> 00:09:26,000
And this is a lot better we can see scanning target and then the actual IP address of my daughter and

128
00:09:26,000 --> 00:09:27,910
then which ports are open.

129
00:09:28,280 --> 00:09:32,620
And it is the exact same for ports that we saw before.

130
00:09:32,630 --> 00:09:34,010
Let's try another target.

131
00:09:34,010 --> 00:09:35,830
Let's specify actually two targets.

132
00:09:35,840 --> 00:09:43,880
Now if I run the program and for this test you can specify the same target as I will which would be

133
00:09:44,000 --> 00:09:49,670
an actual domain name which is called Test BHP dot Vaughn Webb dot com.

134
00:09:50,770 --> 00:09:51,160
OK.

135
00:09:52,780 --> 00:09:58,690
So let's specify this target and also you can specify any other random IP address or domain name if

136
00:09:58,690 --> 00:09:59,460
you want.

137
00:09:59,470 --> 00:10:02,410
In this case I will specify once again my router.

138
00:10:02,410 --> 00:10:07,990
So we have a mixture of the domain name and the IP address so we can see whether this will work properly.

139
00:10:07,990 --> 00:10:09,460
If a press enter.

140
00:10:09,640 --> 00:10:12,820
It will first start off with this domain name right here.

141
00:10:13,330 --> 00:10:19,150
And it will scan for the open ports and then it will proceed to the IP address or my router and scan

142
00:10:19,300 --> 00:10:26,380
the open ports for that front as well so we can see on the first link it found the four ports open for

143
00:10:26,380 --> 00:10:29,640
21 22 53 and 80.

144
00:10:29,680 --> 00:10:32,550
And on my router the same for ports as before.

145
00:10:33,210 --> 00:10:35,900
So every program works correctly.

146
00:10:35,900 --> 00:10:40,480
We're almost close to finishing our program but there is one more thing that we actually want to do.

147
00:10:40,990 --> 00:10:48,850
We want to also print which service is running on an open port for example let's say we want to discover

148
00:10:48,880 --> 00:10:55,650
whether port 80 is running a patch to or some other version of a web server while we can do that by

149
00:10:55,650 --> 00:11:01,950
simply grabbing the banner on an open port and more about that in the next lecture for now and we are

150
00:11:01,950 --> 00:11:08,050
glad that we can scan multiple targets whether they are specified as a domain name or as an IP address.

151
00:11:08,220 --> 00:11:09,920
We can split them by comma.

152
00:11:09,930 --> 00:11:16,110
We can also scan one target if we want and we also print only open ports as we are not really interested

153
00:11:16,320 --> 00:11:17,660
in the closed ports.

154
00:11:17,700 --> 00:11:18,030
OK.

155
00:11:18,150 --> 00:11:22,740
So thank you for watching this lecture and I will see you in the next one by.
