1
00:00:00,510 --> 00:00:00,990
All right.

2
00:00:00,990 --> 00:00:01,830
Welcome back.

3
00:00:01,840 --> 00:00:03,990
Let's continue with our port scanner.

4
00:00:03,990 --> 00:00:04,980
What would it be now.

5
00:00:05,010 --> 00:00:09,900
As you can see from the previous video we only discovered that the port 80 is open on the website that

6
00:00:09,900 --> 00:00:11,280
we scanned.

7
00:00:11,280 --> 00:00:16,260
So what we need to do now is we need to wrap this code inside of a function.

8
00:00:16,260 --> 00:00:18,300
Now let me show you why we are doing that.

9
00:00:18,420 --> 00:00:23,780
If I simply define a function which will be called scan underscore port.

10
00:00:24,210 --> 00:00:28,440
And for those of you who don't know to define the function you simply just type def and then the function

11
00:00:28,440 --> 00:00:35,970
name this function will take two parameters which will be the IP address which when defined at the beginning

12
00:00:35,970 --> 00:00:37,010
of the program.

13
00:00:37,140 --> 00:00:40,340
And it will also be a port.

14
00:00:40,650 --> 00:00:41,750
OK.

15
00:00:41,880 --> 00:00:43,550
We specify two dots.

16
00:00:43,650 --> 00:00:50,840
And now we need to tap all of this code in so it can belong to the function that we created.

17
00:00:51,150 --> 00:00:51,860
OK.

18
00:00:51,990 --> 00:00:53,170
So here it is.

19
00:00:53,250 --> 00:00:58,380
What this function will do is it will scan the port and it will define whether it is open or closed

20
00:01:00,000 --> 00:01:00,360
now.

21
00:01:00,370 --> 00:01:06,370
Another thing that we want to do is we don't really want the ports to be already predetermined for example

22
00:01:06,400 --> 00:01:11,480
let's say that the user of this program wants to scan port 22 which is the a safe port.

23
00:01:11,500 --> 00:01:14,300
Well we want to allow them to actually do that.

24
00:01:14,320 --> 00:01:21,970
So we need to remove this port equals eighteen and also from these comments right here we want to pipe

25
00:01:22,570 --> 00:01:33,070
port and then we are going to type it like this plus string from the port.

26
00:01:33,310 --> 00:01:38,950
And the reason why we're using the string function onto this port variable is because the port variable

27
00:01:38,950 --> 00:01:41,430
will hold an integer value.

28
00:01:41,470 --> 00:01:45,680
Therefore once we actually try to print it we don't get an error.

29
00:01:45,730 --> 00:01:47,970
If we try to print an integer value.

30
00:01:48,000 --> 00:01:53,350
So we need to convert it first string using this SDR function and then we can print this.

31
00:01:53,740 --> 00:02:01,210
So for example in the file if the port is number 23 this will print port 23 it's open.

32
00:02:01,210 --> 00:02:05,250
We also need to do the same right here.

33
00:02:05,690 --> 00:02:07,540
If string from Port

34
00:02:10,140 --> 00:02:16,900
OK so Port 23 is closed and now let's there's no function but let's add a little bit of a twist to it.

35
00:02:16,930 --> 00:02:22,770
So what we want to do is we want to scan first 10 ports on our Web site.

36
00:02:22,770 --> 00:02:23,370
All right.

37
00:02:23,380 --> 00:02:25,050
So how can we do that.

38
00:02:25,090 --> 00:02:28,990
Well we don't have a port specified at all.

39
00:02:28,990 --> 00:02:36,490
So we need to iterate over numbers 1 10 and then specify for each number that the port is equal that

40
00:02:36,490 --> 00:02:38,260
exact number.

41
00:02:38,260 --> 00:02:39,310
Let me show you what I mean.

42
00:02:39,370 --> 00:02:51,010
So right here if I go all the way down and below the function I specify for ports in the range 1 to

43
00:02:51,010 --> 00:02:52,120
10.

44
00:02:53,200 --> 00:03:04,540
I want to perform a function scan helps underscore port on the IP address with the port number.

45
00:03:04,540 --> 00:03:09,250
So what this will do is it will go for port in range from 1 to 10.

46
00:03:09,250 --> 00:03:11,380
So first of all ports would be number one.

47
00:03:11,380 --> 00:03:18,520
We want to scan the IP address with the port equal to 1 then it will perform this task right here.

48
00:03:18,520 --> 00:03:20,180
Then it will go back.

49
00:03:20,200 --> 00:03:25,990
Change the port variable to be equal to two and then it will perform the same task just with the port

50
00:03:25,990 --> 00:03:32,460
number equal to to also what we want to do is we want to copy this copy.

51
00:03:32,470 --> 00:03:38,990
Then we can delete it and we can paste it below the function right here.

52
00:03:39,600 --> 00:03:40,530
OK.

53
00:03:40,620 --> 00:03:43,190
Now let's see whether this works.

54
00:03:43,200 --> 00:03:49,030
So once again for this feel free to scan any websites you want I will simply just go with the same Web

55
00:03:49,030 --> 00:03:50,930
site that we used in the previous video.

56
00:03:51,060 --> 00:03:57,660
And once again in order to discover the IP address of the link we simply just type and look up and then

57
00:03:59,140 --> 00:04:02,360
then the link to the actual Web site.

58
00:04:02,580 --> 00:04:03,030
Copy.

59
00:04:03,090 --> 00:04:03,900
IP address

60
00:04:06,480 --> 00:04:10,630
copied and then let's run the program.

61
00:04:13,780 --> 00:04:14,780
And third target.

62
00:04:14,810 --> 00:04:24,070
Can we select the IP address here at this and now it is scanning first then ports.

63
00:04:24,390 --> 00:04:29,010
Now right away you can notice that it's not really printing anything.

64
00:04:29,010 --> 00:04:35,190
It is actually going rather slow and it is still not even finished with the first port.

65
00:04:35,190 --> 00:04:36,300
Now we don't really want this.

66
00:04:36,300 --> 00:04:40,140
We want our port scanner to work faster so how can we fix this.

67
00:04:40,140 --> 00:04:48,780
Well first of all control C onto the program right here and then inside of our scan port function we

68
00:04:48,780 --> 00:04:52,650
need to add another line which will be

69
00:04:55,290 --> 00:05:02,790
sucked out set to time out and we want to set the time out to be equal to zero point five seconds.

70
00:05:02,790 --> 00:05:08,280
Now keep in mind also that the accuracy of the scan will depend on the length of the timeout.

71
00:05:08,370 --> 00:05:13,620
So some ports will take a longer to connect to and some ports will take less to connect to if you simply

72
00:05:13,620 --> 00:05:15,280
just leave it without the timeout.

73
00:05:15,390 --> 00:05:19,970
The accuracy will be the cost the lower the timeout the smaller the accuracy.

74
00:05:20,220 --> 00:05:26,910
But this is a price to want to pay in order to actually scan the target faster so let's see whether

75
00:05:26,910 --> 00:05:27,520
this work.

76
00:05:27,540 --> 00:05:35,160
So item 3 port scanner we paid the IP address and we can see Port 1 is closed and all of the 10 ports

77
00:05:35,220 --> 00:05:37,710
are closed on our website.

78
00:05:37,920 --> 00:05:41,230
So we scan port 1 through 10.

79
00:05:41,270 --> 00:05:41,750
OK.

80
00:05:41,870 --> 00:05:46,860
Now this is probably correct for the website the time scanning but how can we check that while in the

81
00:05:46,860 --> 00:05:51,340
previous video I scan the exact same Web site and this can deport 80.

82
00:05:51,450 --> 00:05:54,790
So how can it check whether this is working correctly.

83
00:05:54,810 --> 00:06:05,760
Well instead of the range 1 through 10 I will simply just type seventy five to eighty five and most

84
00:06:05,760 --> 00:06:09,500
likely all of the ports will be closed except the port 80.

85
00:06:09,750 --> 00:06:11,310
So let's see how this works.

86
00:06:11,310 --> 00:06:19,590
Python 3 port scanner base the IP address all the ports are closed and we have one port open and that

87
00:06:19,590 --> 00:06:20,970
is port 80.

88
00:06:21,630 --> 00:06:22,010
OK.

89
00:06:22,620 --> 00:06:24,840
So our program seems to work really well.

90
00:06:25,610 --> 00:06:25,970
OK.

91
00:06:26,000 --> 00:06:31,830
So we discovered that we need to set the time out in order to actually scan ports faster.

92
00:06:31,830 --> 00:06:38,760
We lose the accuracy but we gain on time in the next video we're going to take a look at how we can

93
00:06:38,760 --> 00:06:45,930
convert the link to an actual IP address for example we're going to take a look at how we can convert

94
00:06:45,990 --> 00:06:49,800
a link of a website to an IP address inside of our program.

95
00:06:49,800 --> 00:06:55,520
So whether the user of this program specifies a link or an IP address this will still work.

96
00:06:55,530 --> 00:06:55,800
OK.

97
00:06:55,800 --> 00:06:58,480
So I hope I see you in the next video and take care.

98
00:06:58,700 --> 00:06:59,010
By.
