1
00:00:00,450 --> 00:00:01,710
Welcome back everyone.

2
00:00:01,710 --> 00:00:03,550
Let's continue with our port scanner.

3
00:00:03,980 --> 00:00:10,110
So what we did by now is we simply just created this function which allows us to scan ports and we also

4
00:00:10,110 --> 00:00:16,230
saw how we can use for loop in order to iterate over certain amount ports and scan each and every one

5
00:00:16,230 --> 00:00:16,530
of them.

6
00:00:17,490 --> 00:00:22,680
But right now let's see how we can implement a function that will allow the user of this program to

7
00:00:22,680 --> 00:00:26,280
specify the domain name as well as the IP address they like.

8
00:00:27,240 --> 00:00:30,720
Well here is where our IP Wine Library comes in.

9
00:00:30,720 --> 00:00:31,900
Help.

10
00:00:32,040 --> 00:00:34,410
So you will notice that this is still great.

11
00:00:34,410 --> 00:00:39,380
That means that we haven't used it inside of our code and that will change now.

12
00:00:39,390 --> 00:00:48,480
So will simply just create the function up here which will be called let's say check underscore IP and

13
00:00:48,480 --> 00:00:53,490
this function will take one parameter which we will specify inside of these brackets and that parameter

14
00:00:53,490 --> 00:00:55,980
will be the IP address.

15
00:00:55,980 --> 00:00:57,310
OK.

16
00:00:57,420 --> 00:01:03,690
Now before we code any of this function we need to specify all the way down what we are going to provide

17
00:01:03,690 --> 00:01:05,210
to this function.

18
00:01:05,280 --> 00:01:08,580
And by that I mean which parameter are we going to send.

19
00:01:08,580 --> 00:01:13,860
Well logically in our case we are going to send the IP address parameter.

20
00:01:13,860 --> 00:01:18,600
Keep in mind that this IP address variable doesn't have to store the IP address.

21
00:01:18,600 --> 00:01:21,190
It can also store the domain name.

22
00:01:22,350 --> 00:01:28,440
So what we need to do is we need to simply just after the user specified the target we'll simply just

23
00:01:28,440 --> 00:01:36,120
call the function check underscore IP and we will paste the IP address inside of that function

24
00:01:38,950 --> 00:01:43,420
then we are going to store all of this inside of a converted

25
00:01:46,090 --> 00:01:51,070
underscore IP and you will see in just a second why we are doing this.

26
00:01:51,070 --> 00:01:54,970
So right here we're going to scan the converted IP address

27
00:01:58,390 --> 00:02:03,770
and the port number OK so let's call the function above.

28
00:02:04,200 --> 00:02:09,930
So obviously we need to use this library right here and this sexual library comes with a specific function

29
00:02:10,020 --> 00:02:11,980
which is simply called IP function.

30
00:02:12,000 --> 00:02:12,360
Okay.

31
00:02:13,170 --> 00:02:20,070
So if I go to my Google Chrome and I have a page open right here which is basically the documentation

32
00:02:20,100 --> 00:02:25,830
of the IP why library we can see that they use right here this IP function in order to convert an IP

33
00:02:25,830 --> 00:02:27,860
address to the IP format.

34
00:02:27,990 --> 00:02:33,600
So in order for our function to work we need to specify inside of the brackets the IP address which

35
00:02:33,600 --> 00:02:40,190
is the parameter of our function if it manages to convert the IP address that means that this works

36
00:02:40,190 --> 00:02:45,990
successfully and that the user actually specified the actual IP address for the target if it gets in

37
00:02:45,990 --> 00:02:49,890
value area that means that the user specified the domain name.

38
00:02:50,010 --> 00:02:52,240
So let's write that right here.

39
00:02:52,290 --> 00:02:54,840
And in case you don't understand we are going to test this.

40
00:02:54,840 --> 00:03:01,710
So don't worry we're going to try to convert the IP address and if it manages we are going to return

41
00:03:01,890 --> 00:03:08,850
simply but we sent to the function which is the IP and in case it doesn't work we are going to get the

42
00:03:09,150 --> 00:03:14,700
value error which means that the user most likely specified the domain name.

43
00:03:15,210 --> 00:03:20,910
And therefore we're going to return a function which belongs to the socket library which allows us to

44
00:03:20,910 --> 00:03:24,660
convert to the actual hostname to the IP address.

45
00:03:24,660 --> 00:03:30,390
So all we need to do is specify that function and call it upon our IP address and we can do that by

46
00:03:30,390 --> 00:03:34,960
simply specifying return socket dot get hosted by name.

47
00:03:36,330 --> 00:03:42,480
And here we specify the hostname or in our case the IP which would paste it to our function.

48
00:03:42,480 --> 00:03:42,800
Okay.

49
00:03:43,230 --> 00:03:45,030
So this is our internal function.

50
00:03:45,060 --> 00:03:51,540
Now let's see inside of a terminal and let's open up our Python 3.

51
00:03:52,530 --> 00:03:58,290
And here we can import IP loops images like this.

52
00:03:58,380 --> 00:04:01,320
First of all I will launch this.

53
00:04:01,320 --> 00:04:11,420
So we can see it better open Python 3 in import or from IP y import IP.

54
00:04:12,240 --> 00:04:19,360
And now let's say we have are variable called IP address and it will be when I do that 168.

55
00:04:19,370 --> 00:04:20,190
That one that one.

56
00:04:20,540 --> 00:04:20,890
Okay.

57
00:04:21,480 --> 00:04:29,910
And now if I simply just call converted IP equals IP from IP address

58
00:04:33,540 --> 00:04:40,780
and I print the converted IP you will see it will still be the same IP address.

59
00:04:40,860 --> 00:04:42,770
So it really didn't change anything.

60
00:04:42,780 --> 00:04:43,650
Therefore.

61
00:04:43,650 --> 00:04:48,960
Right here if it manages to do that we are simply just returning the IP address that we pasted inside

62
00:04:48,960 --> 00:04:52,100
of this function and we are not making any changes to it.

63
00:04:52,830 --> 00:04:58,670
But that is only the case if this user specifies the IP address if the user specifies the domain name.

64
00:04:58,680 --> 00:05:08,560
So let's create a variable called domain name equals and then let's say Google dot com and we tried

65
00:05:08,560 --> 00:05:20,440
the same thing so converted IP equals IP from the domain name and you will see we will get an error

66
00:05:20,980 --> 00:05:23,020
and it will be the value error.

67
00:05:23,380 --> 00:05:28,900
So that is the case right here then we are going to perform to get hosted by name which will retrieve

68
00:05:28,900 --> 00:05:34,310
the IP address of the Google dot com and then we will return the IP address inside of others can import

69
00:05:34,360 --> 00:05:35,590
function.

70
00:05:35,590 --> 00:05:38,280
So that is all there is for this function.

71
00:05:38,290 --> 00:05:40,490
Now let's see whether this works.

72
00:05:41,760 --> 00:05:42,280
OK.

73
00:05:42,400 --> 00:05:43,900
So let's run the program.

74
00:05:43,890 --> 00:05:53,200
Python 3 and then port scanner and to target to scan let's say we enter let's say the same Web site

75
00:05:53,260 --> 00:05:53,860
as before.

76
00:05:54,040 --> 00:05:59,750
Let's not change it right now and instead of the IP address we now enter the domain name.

77
00:06:00,580 --> 00:06:02,680
We're going to leave this to run.

78
00:06:02,680 --> 00:06:07,950
And here we can see that it works successfully as it did manage to find the port 80 open.

79
00:06:08,080 --> 00:06:11,890
We will get the same result even if we scanned with an IP address.

80
00:06:11,890 --> 00:06:15,730
So right now we can specify both the domain name and IP address.

81
00:06:15,790 --> 00:06:16,580
So that is good.

82
00:06:17,410 --> 00:06:22,090
Now in the next video we're going to take a look at how we can specify multiple targets and scan multiple

83
00:06:22,090 --> 00:06:23,860
targets at once.

84
00:06:23,860 --> 00:06:26,460
So we don't have to run our program over and over again.

85
00:06:26,530 --> 00:06:31,960
We can do the same thing just by specifying multiple targets inside of our program and it will scan

86
00:06:31,960 --> 00:06:32,760
them one by one.

87
00:06:33,490 --> 00:06:36,080
So we're going to take a look at that in the next story.

88
00:06:36,100 --> 00:06:40,780
Hope you enjoyed this small lecture and now we'll see you in the next one by.
