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
Okay.
Now we know what a mac address is and how to change it.
What we want to do now is write a Python program or script that will do this for us automatically.
Now, I know you're thinking right now that you don't know anything about Python.
How are you going to write a program that will do this?
Now, like I said, learning programming can get boring if you don't have a purpose.
That's why I want to teach this course by example.
So we're going to start programming from the start, and as we program, I'm going to teach you programming
concepts and how to program in general.
So this is the first proper programming lecture that we're doing, but we're actually going to build
a very simple script that will change the Mac address for us.
Now, from what you know so far, all you have to do to change the Mac address is run these commands.
So if you want to write a program that does this, the first thing that you need to do is be able to
execute Linux commands through that program.
We want our program to be able to execute terminal commands the same way that we are executing them
here by typing the commands manually.
Now, anything that you can think of, there is probably a way to do it in Python or there is probably
a Python module that does that.
So in order to execute system commands, we have a module called sub process in Python.
Now sub process can execute any system commands.
It doesn't have to be Linux commands.
The difference is if you run the script from Windows, it will allow you to execute Windows commands.
If you run the script from Mac, it will allow you to execute Mac commands.
If you run it from Linux, it will allow you to run Linux commands.
Now, since we're running our script from Linux, then we can run the commands that we learned in the
previous lecture and be able to change our Mac address through a Python program.
Now using the module is very simple and we're going to talk about that in a minute.
But before I show you how to use it, I want to show you the module page.
Now, for every Python module, there is a documentation.
The documentation talks about what the module does, the functions included in this module, and how
to use any of these functions and examples and even good practices and things to avoid.
So it's a very good idea to learn how to go over the documentation and learn what modules do because
there is no course online or anywhere that covers Python completely.
There is no way someone can cover everything.
So all we can do is cover Python for hacking, for example, or Python for data processing or even maybe
a general Python course.
But there is no way to cover everything.
So you need to get into the habit of reading and experimenting and learning how modules work.
Once you get comfortable with using a number of modules, using others is very easy and you'd be able
to just read over the documentation and figure out how to use the modules.
Now, we obviously don't expect you to know this right now, but by the end of the course it should
be very easy for you.
So the module that we want to use is called Sub Process.
And like I said, this module allows us to run system commands.
Now each module contains a number of functions that do something similar.
For example, the sub process module, the one that we want to use, contains a number of functions,
all of which allow us to run system commands but in different ways.
For example, some of them will run commands in the background, some of them will run commands in the
foreground and wait for the command to finish executing and so on.
The function that we want to use today is called call.
So the module name is sub process and the function is called call.
This function allows us to run system commands, but it runs the command in the foreground, it doesn't
run it in the background, it doesn't run it in a different thread, and it waits for the command to
finish executing before it moves to the next line.
This is very important because we don't want our script to exit or continue doing other stuff while
it's still trying to change my Mac address.
I wanted to change the Mac address, finish changing it, and then do other stuff.
So that's why we're using the call, because it will not execute anything else until the command that
I give it finishes executing.
Now if we scroll down, you can see that there is two ways of using this function.
We're going to use the second way in here and then we're going to go and use the first one in a different
lecture and talk about the differences.
So for the second weigh in here, I also have the example here.
All you have to do is just type, sop, process, dot, call followed by the command that you want to
run, followed by shell equals true.
So it's very, very simple.
Now let's have a very simple example of the sub process module before we actually use it to change the
MAC address, just to see how the module works.
So I'm just going to go to my machine and I have my pie chart in here and I have already created a project
called Mac Changer.
So I'm just going to create a new file and I'm creating a Python file.
And I'm going to call it Mark.
Change your dot pie.
Okay.
I'm going to add the shebang at the top.
And then the first thing that I need to do is import the sub process module.
So I'm going to have to say import sub process.
So this literally tells Python that I want to use the sub process module, import all the functions
that I can use with this module.
Once I do that, I'm going to use the module by doing sub process.
So this is the module name and then I'm going to put a dot.
And you can see as soon as I put the dot pie chart automatically shows me all the functions that I can
use with this module.
So these are similar to the functions that you see in here.
Now, like I said, the one that I want to use is called call.
And again, as you can see, as soon as I type call, it shows me the arguments or the inputs that this
function takes.
So I'm going to hit enter to select this function and it will auto fill the brackets for me and it's
going to give me a description on how to use this module.
Now I know how to use it, so I'm just going to move my character to the middle.
And in here we're going to put our command between two quotation marks.
So this is a very simple example.
So all we're going to do is just run if config.
Now we know if config shows us the interfaces that are available to our current operating system.
And finally, we're going to put a comma and add the shell argument and we're going to set that to true
so that we can run shell commands through this function.
And that's it.
Our code is done.
So as you can see, it's a very, very simple code and all it's going to do is it's going to import
the sub process module first.
Then we're using the sub process module and we're adding dot call.
And this is the same way with all modules, you put the module name first followed by the function that
you want to use that stored in this module.
So we're using the call function and we're giving it the first argument as the command that we want
to execute.
And in our case right now, we run, we want to run if config.
And secondly, we're giving it the second argument which sets the shell variable to true.
So we can run Linux commands through this function.
Now you can see that py charm is telling me that there is something wrong with this.
And what's wrong in here is that shell should be a small s, not a capital S.
And this is fine right now.
Now, I'm going to save this by doing control s and then we're going to run it.
You can run it from terminal or you can just go to run and run.
And we're going to select this script, which is mark changer.
And as you can see now, the script got executed in here and it just listed for me the result of IFF
config.
So you can see that it executed if config for me.
And then we see all the interfaces that are available to the current operating system.
So this is a very simple example.
I just wanted to show you how to import a module and run a very simple system command.
And then in the next lecture, this is going to make more sense because we're going to use it to write
a script that will change the Mac address for us.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.