Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Now.
Previously, we learned how to allow the user to set variables using the input and the role input functions.
These are really handy, but I think they make more sense if you want to ask the user for something
in the middle of the execution of the program.
Something similar to what the social engineering toolkit does.
But I think for a simple program like this one, it would make more sense if we can get our user to
input the values as arguments.
So what I mean by arguments is it will be cool if we can allow the user to do something like Python
Mike Mac changer dot p and then give me the values by doing interface.
Set it to zero and then do Mac and give me the new Mac.
Now, if we actually want to implement something like this, it's not going to be easy because first
of all, we need to implement some way of reading all of this, everything that comes after the command.
We also need to be able to read the option names or the arguments here, and we need to read the option
values, which is zero and the new mark.
And we also need to display a health message for the person when they don't give arguments or when they
ask for help.
For example, with all of the known commands, if you just do if config help, you'll get a long menu
showing the help and how to use all of the arguments that come with the if config command.
So you can do this.
It's possible that you can write all of this yourself, or you can just use an already made module by
Python, and that's what we're going to do.
So in order to use a module just like sub process, we need to import that module.
So to do that, we're going to do import.
Module name, which is OPPT pass.
So OPPT Pass is the name of the module that allows us to get arguments from the user and pass them and
use them within our code.
Now importing the module doesn't mean that your program is going to automatically use it.
As you can see, it's actually written in Gray right now and it's telling us that it's unused because
we never used this module with our code.
So when you import something, you tell Python that I'm going to use some code that exists within this
module, but you actually have to call it within your code to use it similar to this process when we
called it in here.
So the next step now is to call this module and get our program to recognize user input and parse it.
To do this, we're going to create a parser object so you can think of this object as an entity or a
person that knows everything about parsing and arguments and can handle all of that itself.
So it's a person or an entity that we're going to use in our program that will handle user input for
us.
So to create this object or this entity, we're going to say parser.
Equals OPPT pass, which is the name of the module that we just imported and we want to create an option
parser.
Now Pastor here is just another variable.
So it's similar to interface and new.
The difference is the value that it holds is different than the value that's held in here.
So for example, interface here gets whatever value that is returned by the row input and the row input
returns wherever the person enters and the person enters a sequence of characters for the name of the
interface.
So the interface usually holds a value of a string.
A sequence of characters parser, on the other hand, is going to hold the value of whatever output
pass the option parser returns.
Now notice the name here starts with a capital letter.
This is a naming convention in Python and basically everything that starts with the capital letter means
that it is a class.
And what a class is, it's basically code.
Or you can think of it as rules or a blueprint for the object.
So it determines what we can do with the parser object.
It's basically all the code that can read the user input.
Like I said in here, when you do interface, for example, it's all the code that displays the health
message.
It's all the code that stores the values that the user enters.
All of it is stored in the option parser class, but you can't use the class as is.
You need to create an instance of that class and that's what we're doing here.
We're creating an entity or an object and that object is stored in the parser variable.
Now again, we're going to be using objects a lot throughout the course and as we use them it will become
clearer.
So right now we created an instance of the option parser class, which is an object that can handle
parsing for us.
Now you can think of this parser object as a child, so it has all the abilities that it inherits from
its father, which is the class to handle parsing.
But since it's a child, we still need to tell it what kind of arguments to look for and how to handle
them.
So we're going to start teaching this child by doing parser.
Dot ad option.
And basically what we're doing now is we're giving it the first argument that it can expect from users.
So this argument is going to be dash A to specify the interface.
We're also going to say the user can either give you the AI or they can give you dash dash interface
to specify the interface.
Then we're going to say this equals.
Interface and what we're doing, what we mean by Dest is this is the name where the value of the interface
is going to be stored.
So this is how we're going to be retrieving the user input.
Again, let's keep doing this and it's going to become clearer once we actually get it done.
Finally, we're going to give it the help message to display to the user if they require help.
And we're going to set that to interface to change its mark.
Address.
Okay.
So it's very, very simple so far.
So all we're doing is we're teaching this parser object or child.
We're telling it that I want you to allow the user to enter a value.
That value they can enter it under the dash I or dash dash interface argument, whatever value they
enter, I want you to store it under interface and if the user requires help, then display this help
message to explain what this argument is.
Finally, we're going to tell this child to pass the arguments that it gets from the user.
So to do that, we're going to say parser.
DOT.
And as you can see, when you actually press the dot pie chart will automatically show you all the methods
that you can invoke on this object or this child.
So what we wanted to do is we just wanted to learn or understand what it got so far.
So we wanted to parse arguments.
Now let's go down to our program, and all I'm going to do is I'm just going to do Python.
Mark, change your dot pie and I'm just going to do a dash.
Dash, help.
Okay.
So this is perfect.
Now because we're using OPPT powers and because we created the option parser here you can see that our
program automatically displays a health message when we do dash, dash help.
You can see that this message is given us the usage.
So it's saying we can use this program by doing mac change or dot py followed by the options.
And the options are you can either do dash h or dash dash help to see this help message or you can do
this option.
And this option is the first option that we created in here and added using the add option method.
So you can see that it's telling us to use this option.
You can either use dash I or Dash Dash interface.
So this is what we set in here.
We set it to use either Dash I or Dash Dash interface.
You can also see the health message that we set in here is being displayed in here, telling the user
that you can use this option to set the interface to change its Mac address.
Now this is perfect.
This is exactly what we wanted.
And in the next lecture we'll learn how to add more options to this and how to use the values that the
user input into our program.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.