Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,120 --> 00:00:01,540
Now.
2
00:00:01,540 --> 00:00:09,610
Previously, we learned how to allow the user to set variables using the input and the role input functions.
3
00:00:10,240 --> 00:00:16,270
These are really handy, but I think they make more sense if you want to ask the user for something
4
00:00:16,270 --> 00:00:19,030
in the middle of the execution of the program.
5
00:00:19,210 --> 00:00:23,410
Something similar to what the social engineering toolkit does.
6
00:00:24,040 --> 00:00:30,760
But I think for a simple program like this one, it would make more sense if we can get our user to
7
00:00:30,760 --> 00:00:33,040
input the values as arguments.
8
00:00:33,460 --> 00:00:39,310
So what I mean by arguments is it will be cool if we can allow the user to do something like Python
9
00:00:39,310 --> 00:00:46,090
Mike Mac changer dot p and then give me the values by doing interface.
10
00:00:46,420 --> 00:00:51,940
Set it to zero and then do Mac and give me the new Mac.
11
00:00:53,260 --> 00:00:58,930
Now, if we actually want to implement something like this, it's not going to be easy because first
12
00:00:58,930 --> 00:01:05,530
of all, we need to implement some way of reading all of this, everything that comes after the command.
13
00:01:06,010 --> 00:01:13,600
We also need to be able to read the option names or the arguments here, and we need to read the option
14
00:01:13,600 --> 00:01:16,210
values, which is zero and the new mark.
15
00:01:16,480 --> 00:01:22,750
And we also need to display a health message for the person when they don't give arguments or when they
16
00:01:22,750 --> 00:01:23,800
ask for help.
17
00:01:24,010 --> 00:01:31,540
For example, with all of the known commands, if you just do if config help, you'll get a long menu
18
00:01:31,540 --> 00:01:36,970
showing the help and how to use all of the arguments that come with the if config command.
19
00:01:37,660 --> 00:01:39,300
So you can do this.
20
00:01:39,310 --> 00:01:46,060
It's possible that you can write all of this yourself, or you can just use an already made module by
21
00:01:46,060 --> 00:01:49,210
Python, and that's what we're going to do.
22
00:01:49,600 --> 00:01:54,940
So in order to use a module just like sub process, we need to import that module.
23
00:01:55,300 --> 00:01:57,610
So to do that, we're going to do import.
24
00:01:58,410 --> 00:02:00,810
Module name, which is OPPT pass.
25
00:02:02,650 --> 00:02:10,479
So OPPT Pass is the name of the module that allows us to get arguments from the user and pass them and
26
00:02:10,479 --> 00:02:12,130
use them within our code.
27
00:02:12,790 --> 00:02:18,550
Now importing the module doesn't mean that your program is going to automatically use it.
28
00:02:18,730 --> 00:02:24,490
As you can see, it's actually written in Gray right now and it's telling us that it's unused because
29
00:02:24,490 --> 00:02:27,040
we never used this module with our code.
30
00:02:27,370 --> 00:02:33,730
So when you import something, you tell Python that I'm going to use some code that exists within this
31
00:02:33,730 --> 00:02:39,850
module, but you actually have to call it within your code to use it similar to this process when we
32
00:02:39,850 --> 00:02:41,020
called it in here.
33
00:02:42,210 --> 00:02:50,550
So the next step now is to call this module and get our program to recognize user input and parse it.
34
00:02:51,650 --> 00:02:58,820
To do this, we're going to create a parser object so you can think of this object as an entity or a
35
00:02:58,820 --> 00:03:05,810
person that knows everything about parsing and arguments and can handle all of that itself.
36
00:03:06,230 --> 00:03:12,770
So it's a person or an entity that we're going to use in our program that will handle user input for
37
00:03:12,770 --> 00:03:13,340
us.
38
00:03:14,090 --> 00:03:18,440
So to create this object or this entity, we're going to say parser.
39
00:03:19,830 --> 00:03:28,110
Equals OPPT pass, which is the name of the module that we just imported and we want to create an option
40
00:03:28,110 --> 00:03:29,010
parser.
41
00:03:30,900 --> 00:03:33,930
Now Pastor here is just another variable.
42
00:03:33,930 --> 00:03:36,660
So it's similar to interface and new.
43
00:03:37,950 --> 00:03:43,770
The difference is the value that it holds is different than the value that's held in here.
44
00:03:44,010 --> 00:03:51,270
So for example, interface here gets whatever value that is returned by the row input and the row input
45
00:03:51,270 --> 00:03:58,080
returns wherever the person enters and the person enters a sequence of characters for the name of the
46
00:03:58,080 --> 00:03:58,950
interface.
47
00:03:58,950 --> 00:04:03,330
So the interface usually holds a value of a string.
48
00:04:03,450 --> 00:04:10,200
A sequence of characters parser, on the other hand, is going to hold the value of whatever output
49
00:04:10,200 --> 00:04:13,170
pass the option parser returns.
50
00:04:13,650 --> 00:04:16,860
Now notice the name here starts with a capital letter.
51
00:04:17,130 --> 00:04:24,480
This is a naming convention in Python and basically everything that starts with the capital letter means
52
00:04:24,480 --> 00:04:26,400
that it is a class.
53
00:04:26,940 --> 00:04:30,000
And what a class is, it's basically code.
54
00:04:30,000 --> 00:04:35,310
Or you can think of it as rules or a blueprint for the object.
55
00:04:35,310 --> 00:04:39,630
So it determines what we can do with the parser object.
56
00:04:39,660 --> 00:04:43,800
It's basically all the code that can read the user input.
57
00:04:43,800 --> 00:04:50,580
Like I said in here, when you do interface, for example, it's all the code that displays the health
58
00:04:50,580 --> 00:04:51,270
message.
59
00:04:51,270 --> 00:04:54,930
It's all the code that stores the values that the user enters.
60
00:04:54,930 --> 00:05:00,990
All of it is stored in the option parser class, but you can't use the class as is.
61
00:05:00,990 --> 00:05:05,670
You need to create an instance of that class and that's what we're doing here.
62
00:05:05,670 --> 00:05:12,390
We're creating an entity or an object and that object is stored in the parser variable.
63
00:05:12,870 --> 00:05:18,360
Now again, we're going to be using objects a lot throughout the course and as we use them it will become
64
00:05:18,360 --> 00:05:19,050
clearer.
65
00:05:19,590 --> 00:05:26,880
So right now we created an instance of the option parser class, which is an object that can handle
66
00:05:26,880 --> 00:05:28,200
parsing for us.
67
00:05:29,250 --> 00:05:36,870
Now you can think of this parser object as a child, so it has all the abilities that it inherits from
68
00:05:36,870 --> 00:05:40,730
its father, which is the class to handle parsing.
69
00:05:40,740 --> 00:05:47,430
But since it's a child, we still need to tell it what kind of arguments to look for and how to handle
70
00:05:47,430 --> 00:05:47,850
them.
71
00:05:48,330 --> 00:05:53,010
So we're going to start teaching this child by doing parser.
72
00:05:54,490 --> 00:05:56,470
Dot ad option.
73
00:05:57,460 --> 00:06:05,020
And basically what we're doing now is we're giving it the first argument that it can expect from users.
74
00:06:05,620 --> 00:06:11,920
So this argument is going to be dash A to specify the interface.
75
00:06:12,930 --> 00:06:20,640
We're also going to say the user can either give you the AI or they can give you dash dash interface
76
00:06:20,640 --> 00:06:22,650
to specify the interface.
77
00:06:23,490 --> 00:06:26,850
Then we're going to say this equals.
78
00:06:27,590 --> 00:06:36,590
Interface and what we're doing, what we mean by Dest is this is the name where the value of the interface
79
00:06:36,590 --> 00:06:37,840
is going to be stored.
80
00:06:37,850 --> 00:06:41,930
So this is how we're going to be retrieving the user input.
81
00:06:42,500 --> 00:06:47,390
Again, let's keep doing this and it's going to become clearer once we actually get it done.
82
00:06:48,200 --> 00:06:54,350
Finally, we're going to give it the help message to display to the user if they require help.
83
00:06:55,070 --> 00:07:00,740
And we're going to set that to interface to change its mark.
84
00:07:02,080 --> 00:07:02,890
Address.
85
00:07:04,040 --> 00:07:04,360
Okay.
86
00:07:04,450 --> 00:07:06,750
So it's very, very simple so far.
87
00:07:06,760 --> 00:07:10,540
So all we're doing is we're teaching this parser object or child.
88
00:07:10,540 --> 00:07:15,670
We're telling it that I want you to allow the user to enter a value.
89
00:07:16,030 --> 00:07:24,010
That value they can enter it under the dash I or dash dash interface argument, whatever value they
90
00:07:24,010 --> 00:07:32,440
enter, I want you to store it under interface and if the user requires help, then display this help
91
00:07:32,440 --> 00:07:35,890
message to explain what this argument is.
92
00:07:37,770 --> 00:07:44,490
Finally, we're going to tell this child to pass the arguments that it gets from the user.
93
00:07:44,670 --> 00:07:47,130
So to do that, we're going to say parser.
94
00:07:48,500 --> 00:07:49,280
DOT.
95
00:07:49,490 --> 00:07:55,490
And as you can see, when you actually press the dot pie chart will automatically show you all the methods
96
00:07:55,490 --> 00:07:59,180
that you can invoke on this object or this child.
97
00:07:59,360 --> 00:08:05,160
So what we wanted to do is we just wanted to learn or understand what it got so far.
98
00:08:05,180 --> 00:08:07,760
So we wanted to parse arguments.
99
00:08:08,720 --> 00:08:14,630
Now let's go down to our program, and all I'm going to do is I'm just going to do Python.
100
00:08:15,230 --> 00:08:19,010
Mark, change your dot pie and I'm just going to do a dash.
101
00:08:19,010 --> 00:08:19,970
Dash, help.
102
00:08:21,340 --> 00:08:21,730
Okay.
103
00:08:21,730 --> 00:08:23,110
So this is perfect.
104
00:08:24,190 --> 00:08:31,540
Now because we're using OPPT powers and because we created the option parser here you can see that our
105
00:08:31,540 --> 00:08:36,700
program automatically displays a health message when we do dash, dash help.
106
00:08:37,419 --> 00:08:40,030
You can see that this message is given us the usage.
107
00:08:40,030 --> 00:08:46,060
So it's saying we can use this program by doing mac change or dot py followed by the options.
108
00:08:46,750 --> 00:08:55,210
And the options are you can either do dash h or dash dash help to see this help message or you can do
109
00:08:55,210 --> 00:08:56,230
this option.
110
00:08:56,320 --> 00:09:03,730
And this option is the first option that we created in here and added using the add option method.
111
00:09:04,540 --> 00:09:07,210
So you can see that it's telling us to use this option.
112
00:09:07,210 --> 00:09:11,500
You can either use dash I or Dash Dash interface.
113
00:09:12,250 --> 00:09:14,350
So this is what we set in here.
114
00:09:14,350 --> 00:09:19,150
We set it to use either Dash I or Dash Dash interface.
115
00:09:19,810 --> 00:09:25,810
You can also see the health message that we set in here is being displayed in here, telling the user
116
00:09:25,810 --> 00:09:31,210
that you can use this option to set the interface to change its Mac address.
117
00:09:31,900 --> 00:09:33,040
Now this is perfect.
118
00:09:33,040 --> 00:09:34,900
This is exactly what we wanted.
119
00:09:34,900 --> 00:09:41,290
And in the next lecture we'll learn how to add more options to this and how to use the values that the
120
00:09:41,290 --> 00:09:43,630
user input into our program.
12228
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.