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.
So now we have a script that can change the Mac address of 102001122334466.
Now, as you can see, this is not a great script because all we can use it for is to change the Mac
address of LAN zero to this specific Mac address.
So we can't use it to change the Mac address of any other interface, and we can't change it to any
other Mac address other than this one unless you come in and manually change the code here, which is
not a good practice.
So a better implementation would be to use variables for the places that vary.
So we have the line zero.
Here is a variable.
The value of it can change depending on the interface that the person wants to use.
So if you want to change the Mac address of to zero, you can set it to zero.
If you want to change the MAC address of line one.
If you have two wireless interfaces, then you can change for line one.
Therefore, this value right here is a variable and it's better to use a variable for that.
Same goes for the Mac address here.
As described before, if you're actually using this in real life, you'd want to be always using a different
Mac address, and you won't always want to use the same Mac address over and over.
Therefore, it will make sense to use a variable for the value of the Mac address in here as well.
And what I mean by a variable is a value that can be easily changed through the user input or through
the program itself.
Now variables are used everywhere in programming, in all programming languages, not only in Python,
and they are very useful.
You can't really write a program without a variable.
So technically speaking, a variable is a location in memory that contains a certain value.
But what we actually mean by that is it's a word or a name that stores a value, something very similar
to when we use X and Y in maths.
We always used variables and we always got questions in exams to find X and solve equations and all
that.
And all the letters in these equations are variables.
So you can think of a variable as a box that contains a certain value or as a container that contains
a certain value.
Now, a very simple example that I have here is we can just do in Python set x equals one, then x will
hold the value of one.
So you can say y is equal to x plus x, that means y is equal to one plus one.
Then Y is going to have a value of two.
And then you can print Y and you'll see two on screen.
Now this is very simple and not useful, and that's why programming can be boring if you don't have
a purpose.
So we're not going to be doing this.
What we are going to do is adopt this in our cool script in here.
So we want line zero to be a variable and we want the Mac to be a variable.
So all we have to do is before we use these variables, type them in here.
So we're going to create our first variable.
And to create that, all you have to do is just type its name.
Now in maths, we're used to use X and Y when we're using variables.
You can do that with Python, but it's not a good practice.
It's better to name your variables meaningful names.
So names that are relevant to the value that stored in that variable.
You can use letters and numbers and variables, but it has to start with a letter or an underscore.
You can use the underscore anywhere within the variable name, and the names are case sensitive.
So since we want to use meaningful names, a very good variable name would be interface.
To hold the value for the interface.
Now our interface is line zero.
So we're going to initialize that to line zero.
Now we have a variable or a box named interface and it has a value of zero.
So everywhere we use line zero, we can just substitute interface and Python as it interprets the code.
It will replace any occurrence of interface with the value that we set it to, which is line zero.
Now before I use that in the code here, because this is something new, I'm going to use it in a print
statement.
It's actually a really good idea as you go along with coding to print stuff as your programming so you
can see what's the value for that variable at this line or at this moment of time.
So it's a good practice and it will actually make you understand the idea of variables more and you'll
get more comfortable with it.
So first of all, I'm just going to comment all of this basically commenting a line means that we're
telling Python to ignore this line and don't treat it as code.
To do that, all we have to do is just put the hash symbol before the line or you can press control
and forward slash and that will automatically add comments to multiple lines.
So whenever we run this code, all of this will be ignored.
And what I want to do in here, I actually want to use a very simple print statement.
And inside it, we're just going to give a notification to the user and we're just going to say change
in Mac address for.
And then I want to say the name of the interface that the script will work on.
So we have to use the interface variable in here.
And to do that, all we have to do is append this variable to the string.
So like we said before, any sequence of characters enclosed between two quotations is treated as a
string or is called a string in Python.
Now, since our variable is a string as well, as you can see, it's a sequence of characters as well.
So all we have to do in Python is just put a plus followed by the the variable name, which is interface.
And that's it.
Now, when we interpret this, let's go down and do it.
So if we just do Python Mac change or dot p, you'll see it's going to print for me changing mac address
for and instead of interface here it replaced it with the value that we have here, which is line zero.
Now this is cool, but if you look at our code here and remember what we said, we also want to use
a variable for the Mac address value.
So let's do that.
Let's call this variable now new Mac.
And let's set that to 001122, three, three, four, four, and we'll set it to seven seven this time.
So it's different than the last time.
Now, again, simply by doing this, we created a new variable or a new box or a new container that's
called new mark.
And its value is a sequence of characters enclosed between two quotations.
So it's a string.
Now let's append that to our string in here.
So we have the string in the print statement.
And I want to say changing Mac address for interface.
So four lines zero two and then put the value of the Mac, which we're going to change the current MAC
address to.
So again, just to append the string, all we have to do is just put a plus followed by the rest of
this string, which is we're saying change in Mac address for Interface two.
And then we want to put the value of the of the new Mac address.
Again, all we have to do is put a plus followed by the new Mac, and that's it.
So all we're saying is change your Mac address for we close the quotation and then we put our variable,
because if we put the variable inside the quotation, python will think this is part of the string and
it will just print it as interface.
It won't substitute its value with line zero.
Same goes with using the new Mac in here.
If you put that inside the quotation, it will just treat that as a string and it won't print its value.
So now if we go down and just run our code again.
As you can see, it's printing changing mac address for line zero so substituted the value of interface
with line zero with the value that we initialize the two and it's changing it to the new Mac.
Again, it's substituting the new Mac variable with this.
Now just as a quick test, I know I spend a bit too much time on this, but just as a quick test, if
I put the new Mac here inside the string and run this.
You'll see that the interface will be substituted with the value of line zero.
But Python will not know that new Mac is a variable.
It will just print it as part of the string because we put it inside the quotation mark.
So that's it for now.
Just a quick introduction to variables.
I wanted to show you how to use it in a print statement and get into the habit of printing the value
of variables.
Because when you have longer code, it might be a smart idea to print it as you're writing the code
to make sure that its value is still what you want it to be.
And the next lecture will use the variables that we just created in the code so that we can change the
Mac address and the interface quickly using these variables.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.