WEBVTT - This file was automatically generated by VIMEO

0
00:00:14.100 --> 00:00:14.800
Hello, everyone.

1
00:00:16.200 --> 00:00:18.900
And welcome to python with nmap.

2
00:00:19.700 --> 00:00:23.100
So here we are going to write a very cool program in

3
00:00:22.100 --> 00:00:25.800
 which we are going to run a port

4
00:00:25.800 --> 00:00:29.000
 scanner which will be made by us. So

5
00:00:28.100 --> 00:00:31.700
 we are going to write a python Port scanner

6
00:00:31.700 --> 00:00:34.700
 using nmap. And then we are going to run a

7
00:00:34.700 --> 00:00:37.700
 port scan on to a public network and

8
00:00:37.700 --> 00:00:39.500
 our localhost Network.

9
00:00:40.400 --> 00:00:43.300
Cool, so I have taken up sublime.

10
00:00:44.300 --> 00:00:47.400
Text editor you can use any IDE that you

11
00:00:47.400 --> 00:00:47.500
 want.

12
00:00:49.100 --> 00:00:52.800
So I have written first import and map for importing

13
00:00:52.800 --> 00:00:54.400
 the nmap library.

14
00:00:55.600 --> 00:00:58.400
Then I have written begin equals to

15
00:00:58.400 --> 00:01:00.800
 75 and end equals to 80.

16
00:01:01.600 --> 00:01:04.200
So these are the range of ports to be

17
00:01:04.200 --> 00:01:04.800
 scanned.

18
00:01:05.500 --> 00:01:08.400
I want to scan the first Port that

19
00:01:08.400 --> 00:01:11.700
 should start from 75 and then 80 so I

20
00:01:11.700 --> 00:01:14.800
 have made two variables which we are going to assign two

21
00:01:14.800 --> 00:01:17.500
 values. There are 75 and 80.

22
00:01:18.900 --> 00:01:19.300
Perfect.

23
00:01:20.000 --> 00:01:20.400
next

24
00:01:21.500 --> 00:01:24.200
Target equals to Raw input enter your

25
00:01:24.200 --> 00:01:27.500
 target. So we are assigning the target IP

26
00:01:27.500 --> 00:01:30.600
 address over here that need to be scanned through a

27
00:01:30.600 --> 00:01:32.600
 variable called as Target.

28
00:01:33.400 --> 00:01:36.100
Here we have assigned a new variable and we

29
00:01:36.100 --> 00:01:39.300
 are going to take a raw input from the user and going to

30
00:01:39.300 --> 00:01:42.600
 utilize that particular input which will be obviously

31
00:01:42.600 --> 00:01:45.200
 IP address to be scanned.

32
00:01:47.500 --> 00:01:47.900
next

33
00:01:48.800 --> 00:01:51.700
we are going to instantiate a port

34
00:01:51.700 --> 00:01:54.400
 scanner object as you can see over here, which is

35
00:01:54.400 --> 00:01:56.600
 nmap dot Port scanner.

36
00:01:58.100 --> 00:01:59.100
perfect next

37
00:02:00.900 --> 00:02:03.100
Here we are going to run a for Loop.

38
00:02:03.100 --> 00:02:06.600
 So I have taken a for Loop for iteration. So I'm

39
00:02:06.600 --> 00:02:09.900
 using a variable that is I range

40
00:02:09.900 --> 00:02:12.500
 method which accepts two parameters, which

41
00:02:12.500 --> 00:02:14.200
 is begin and end.

42
00:02:15.200 --> 00:02:18.600
So the first one is begin second one is end, but the

43
00:02:18.600 --> 00:02:21.100
 value is not included. So I

44
00:02:21.100 --> 00:02:24.200
 want to scan the port 80 as well. If I do

45
00:02:24.200 --> 00:02:27.900
 not add plus 1 it will not scan Port 80

46
00:02:27.900 --> 00:02:28.600
 and it will only

47
00:02:29.400 --> 00:02:32.400
Scan till 79. So I want to include

48
00:02:32.400 --> 00:02:35.500
 that particular Port as well. So and plus 1

49
00:02:35.500 --> 00:02:37.600
 into this particular for Loop.

50
00:02:38.800 --> 00:02:40.900
Now we have included our Port 80 as well.

51
00:02:42.600 --> 00:02:45.100
Let's move forward and here you can

52
00:02:45.100 --> 00:02:48.900
 see result equals to scanner.scan wherein

53
00:02:48.900 --> 00:02:51.700
 Target comma string of

54
00:02:51.700 --> 00:02:54.800
 I so what we are doing actually here. So we

55
00:02:54.800 --> 00:02:56.500
 are going to scan the Target Port.

56
00:02:57.600 --> 00:03:00.600
So we have made a scan function which requires

57
00:03:00.600 --> 00:03:01.500
 two parameter.

58
00:03:02.100 --> 00:03:04.600
First is the IP to be scanned. Okay?

59
00:03:05.900 --> 00:03:06.900
the next one is

60
00:03:07.900 --> 00:03:10.700
Str which is basically nothing but we

61
00:03:10.700 --> 00:03:13.300
 are typecasting I into a string format.

62
00:03:15.200 --> 00:03:15.500
next

63
00:03:16.800 --> 00:03:20.100
Is a result equals to this and

64
00:03:19.100 --> 00:03:22.600
 the result will be containing several information

65
00:03:22.600 --> 00:03:25.700
 as our output in Json, but from that

66
00:03:25.700 --> 00:03:29.000
 we only need limited output. So basically

67
00:03:28.400 --> 00:03:31.100
 we have to just check if the port is open

68
00:03:31.100 --> 00:03:35.000
 or closed. So we will access only that required information. So

69
00:03:34.200 --> 00:03:38.100
 we are going to write it this way wherein

70
00:03:37.100 --> 00:03:40.600
 we are going to get scan in our output

71
00:03:40.600 --> 00:03:41.000
 and

72
00:03:42.600 --> 00:03:45.300
The TCP as well as the state out of

73
00:03:45.300 --> 00:03:48.300
 which we only want to show the results which are

74
00:03:48.300 --> 00:03:49.600
 accessing two values.

75
00:03:50.500 --> 00:03:53.500
The first one is I that is the port number as you

76
00:03:53.500 --> 00:03:56.300
 can see over here. So Port will give the port

77
00:03:56.300 --> 00:03:59.600
 number which starts from 75 to

78
00:03:59.600 --> 00:04:02.100
 80 as we saw in the beginning.

79
00:04:02.800 --> 00:04:05.700
This is the begin variable and this is the end variable.

80
00:04:05.700 --> 00:04:07.800
 The next one is state.

81
00:04:08.600 --> 00:04:11.300
Which is basically the result and

82
00:04:11.300 --> 00:04:14.000
 we will get the port status either. It is

83
00:04:14.300 --> 00:04:16.100
 open closed or filtered.

84
00:04:17.300 --> 00:04:20.400
Yeah, so now we have understood the code. It is quite pretty

85
00:04:20.400 --> 00:04:23.200
 simple. Now. Let us quickly jump back over here

86
00:04:23.200 --> 00:04:27.000
 and let's try to execute over particular Python

87
00:04:26.500 --> 00:04:29.600
 program and run our Port scanner.

88
00:04:29.600 --> 00:04:33.800
 So I have saved this ads PS sportscana.py. Let

89
00:04:33.800 --> 00:04:36.700
 me just run it and it will ask me enter

90
00:04:36.700 --> 00:04:37.100
 your target.

91
00:04:38.300 --> 00:04:40.600
If you remember if you go back to the code.

92
00:04:41.300 --> 00:04:44.700
This is the raw input which is asking us

93
00:04:44.700 --> 00:04:47.600
 to enter our Target. So let

94
00:04:47.600 --> 00:04:48.300
 us quickly type.

95
00:04:49.200 --> 00:04:50.200
our loopback address

96
00:04:51.700 --> 00:04:53.400
of this machine and hit enter.

97
00:04:54.400 --> 00:04:58.100
As you can see it has started scanning from Port 75 to

98
00:04:57.100 --> 00:05:00.300
 Port 80 and all the

99
00:05:00.300 --> 00:05:03.300
 ports are closed for now as there are

100
00:05:03.300 --> 00:05:06.400
 no open ports into this machine. So let us quickly open

101
00:05:06.400 --> 00:05:10.400
 one port wherein I'm going to use Python Library

102
00:05:09.400 --> 00:05:12.400
 as well. So I'm

103
00:05:12.400 --> 00:05:17.000
 going to use the python module which is a simple HTTP server.

104
00:05:16.100 --> 00:05:19.600
 So this particular module is used

105
00:05:19.600 --> 00:05:21.100
 to create a

106
00:05:22.200 --> 00:05:25.400
Simple HTTP server using python so

107
00:05:25.400 --> 00:05:27.200
 I have used the port 80.

108
00:05:28.400 --> 00:05:31.400
So as you can see, the server has successfully started on

109
00:05:31.400 --> 00:05:34.300
 Port 80 now, let us scan and see

110
00:05:34.300 --> 00:05:37.400
 if our Port scanner

111
00:05:37.400 --> 00:05:40.300
 detects that if Port 80 is open or not. So

112
00:05:40.300 --> 00:05:41.100
 I will just hit enter.

113
00:05:41.900 --> 00:05:43.700
Again, let me type my loopback IP address.

114
00:05:45.400 --> 00:05:47.000
And let's wait for the scan.

115
00:05:48.800 --> 00:05:51.900
As you can see it has scanned for 75 76 77

116
00:05:51.900 --> 00:05:54.100
 78 79 and we

117
00:05:54.100 --> 00:05:57.700
 are waiting for 80 and we have got the result as

118
00:05:57.700 --> 00:05:58.100
 open.

119
00:05:59.400 --> 00:06:02.800
Perfect. So we have got the result as open because Port

120
00:06:02.800 --> 00:06:05.500
 80 was scanned and over

121
00:06:05.500 --> 00:06:09.100
 here. You can see we have got a request from

122
00:06:08.100 --> 00:06:10.200
 nmap.

123
00:06:11.200 --> 00:06:12.300
As you can see over here.

124
00:06:14.200 --> 00:06:18.400
And and the particular request was to check that if

125
00:06:17.400 --> 00:06:21.000
 the port is open or not. So nmap tries

126
00:06:20.200 --> 00:06:23.300
 to send a particular request as you

127
00:06:23.300 --> 00:06:23.900
 can see over here.

128
00:06:24.800 --> 00:06:27.300
Multiple requests are being sent to identify the port

129
00:06:27.300 --> 00:06:30.700
 status and end map as identify that that

130
00:06:30.700 --> 00:06:33.600
 particular port is open and communicating with

131
00:06:33.600 --> 00:06:36.300
 nmap and hence given that result

132
00:06:36.300 --> 00:06:37.700
 in the output as open.

133
00:06:38.700 --> 00:06:41.600
So this was one of the very simplest way to make your own

134
00:06:41.600 --> 00:06:43.300
 port scanner in Python.

135
00:06:43.900 --> 00:06:45.200
So I hope you guys understood.

136
00:06:46.300 --> 00:06:46.400
Thank you.
