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
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.
So from the previous lectures, we know how to change the Mac address using these three commands by
doing if config lan zero down if config lan zero whether followed by the MAC address that we want to
change our MAC address to and then we do if config lan zero up to enable our interface.
We also learned how to execute system commands from Python using the SAP process module.
So we're going to combine these two things and write a program that will change the Mac address for
us.
So first of all, I'm just going to close this from here and then all we have to do right now is change
if config in here with the commands that we executed here.
So the first command that we want to run is going to be if config.
Land zero down.
Then you can actually do control DX to duplicate the line that you're currently at.
So I'm going to do Control D right here.
And as you can see, I have a new line exactly similar to the previous line.
And in here we're going to do if config line 0hw ether and then input the MAC address and let's set
it this time to zero zero.
One, one, two, two, three, three, four, four, and we'll set it to six, six this time so we
can differentiate it from the previous one.
And finally, I'm going to do Control DX again because I'm lazy.
So a duplicates the line for me.
And the final command is going to be if config lan zero up to enable the interface and that's it.
We're done.
Very, very simple.
So very similar to what we did before.
We're importing this process module first and then we're using the same function, which is the call
function which allows us to run system commands and we're on Linux so we can run any Linux commands.
And we know that these commands allow us to change the Mac address.
We put the interface down first, then we set the MAC address that we want to use by doing if config
lan zero hash table other followed by the mac address.
And then we do if config lan zero up to enable the MAC address.
Now if we execute this script from terminal, the script should change the MAC address for us and we
won't have to run these three commands to do it.
So I can run it by going to run here and then run.
But I actually don't want to do that.
I want to run it from terminal because I actually like running stuff from terminal more because I can
run other commands and so that we can run if config after it and make sure that the MAC address did
actually change.
So I'm going to go to my terminal and I'm going to navigate to where this project is stored.
Now, if we go up here just for a second and hover over here, you can see that this project is stored
in my user home.
PY Charm mac changer.
So I'm going to do see the pie chart projects and by the way you can just press tab as you're typing
a command and it will autocomplete for you.
So all I have to do is type Mac and Tab and as you can see, it automatically auto completes the mac
changer.
Now, if I do, LZ, here to list all the files you can see, I have my mac changer script in here.
And to run this script, as usual, all you have to do is do python mac.
Change your dot py hit enter.
And this didn't show us any errors.
So this is very good.
This means that things did actually work.
And now if we do if config lands zero.
You can see that our Mac address got changed to 001122334466 instead of five five.
So this means that our code in here worked and we managed to execute these three system commands through
our Python script.
Now I know what you're thinking.
This is very simple.
All we're doing is just running system commands.
Doesn't really show the power of Python, but we're still at the very start of the lectures.
I'm actually going to spend a little bit more time on this script to cover a lot of basics about Python
programming.
So in the next lectures, we're going to be building up on this very simple script.
And as we do that, I'm going to teach you conditional statements, variables, regex and more.
And this is the style I'm going to follow throughout the whole course.
We're going to be, first of all, creating a script that does something useful, and then we'll build
up on that.
So this won't be the only script that we create, but we're actually spent some time working and adding
features to this script because as I add features, I want to cover Python basics so that I can teach
you more advanced Python programming in the next sections and build more advanced Python programs.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.