Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,030 --> 00:00:01,600
Okay.
2
00:00:01,600 --> 00:00:07,360
So from the previous lectures, we know how to change the Mac address using these three commands by
3
00:00:07,360 --> 00:00:14,020
doing if config lan zero down if config lan zero whether followed by the MAC address that we want to
4
00:00:14,020 --> 00:00:20,620
change our MAC address to and then we do if config lan zero up to enable our interface.
5
00:00:21,460 --> 00:00:27,610
We also learned how to execute system commands from Python using the SAP process module.
6
00:00:27,730 --> 00:00:34,570
So we're going to combine these two things and write a program that will change the Mac address for
7
00:00:34,570 --> 00:00:35,080
us.
8
00:00:35,440 --> 00:00:43,450
So first of all, I'm just going to close this from here and then all we have to do right now is change
9
00:00:43,450 --> 00:00:47,710
if config in here with the commands that we executed here.
10
00:00:48,550 --> 00:00:53,080
So the first command that we want to run is going to be if config.
11
00:00:54,260 --> 00:00:56,690
Land zero down.
12
00:00:57,680 --> 00:01:03,940
Then you can actually do control DX to duplicate the line that you're currently at.
13
00:01:03,950 --> 00:01:06,790
So I'm going to do Control D right here.
14
00:01:06,800 --> 00:01:11,120
And as you can see, I have a new line exactly similar to the previous line.
15
00:01:11,600 --> 00:01:22,460
And in here we're going to do if config line 0hw ether and then input the MAC address and let's set
16
00:01:22,460 --> 00:01:24,560
it this time to zero zero.
17
00:01:25,270 --> 00:01:32,320
One, one, two, two, three, three, four, four, and we'll set it to six, six this time so we
18
00:01:32,320 --> 00:01:34,750
can differentiate it from the previous one.
19
00:01:35,530 --> 00:01:39,850
And finally, I'm going to do Control DX again because I'm lazy.
20
00:01:39,850 --> 00:01:41,870
So a duplicates the line for me.
21
00:01:41,890 --> 00:01:49,270
And the final command is going to be if config lan zero up to enable the interface and that's it.
22
00:01:49,270 --> 00:01:49,900
We're done.
23
00:01:49,930 --> 00:01:51,160
Very, very simple.
24
00:01:51,160 --> 00:01:53,530
So very similar to what we did before.
25
00:01:53,560 --> 00:01:58,990
We're importing this process module first and then we're using the same function, which is the call
26
00:01:58,990 --> 00:02:05,590
function which allows us to run system commands and we're on Linux so we can run any Linux commands.
27
00:02:05,680 --> 00:02:09,270
And we know that these commands allow us to change the Mac address.
28
00:02:09,280 --> 00:02:16,840
We put the interface down first, then we set the MAC address that we want to use by doing if config
29
00:02:16,840 --> 00:02:20,170
lan zero hash table other followed by the mac address.
30
00:02:20,440 --> 00:02:25,150
And then we do if config lan zero up to enable the MAC address.
31
00:02:25,720 --> 00:02:32,260
Now if we execute this script from terminal, the script should change the MAC address for us and we
32
00:02:32,260 --> 00:02:35,020
won't have to run these three commands to do it.
33
00:02:35,680 --> 00:02:39,580
So I can run it by going to run here and then run.
34
00:02:39,580 --> 00:02:41,020
But I actually don't want to do that.
35
00:02:41,020 --> 00:02:46,060
I want to run it from terminal because I actually like running stuff from terminal more because I can
36
00:02:46,060 --> 00:02:52,480
run other commands and so that we can run if config after it and make sure that the MAC address did
37
00:02:52,480 --> 00:02:53,740
actually change.
38
00:02:54,160 --> 00:03:00,460
So I'm going to go to my terminal and I'm going to navigate to where this project is stored.
39
00:03:00,580 --> 00:03:06,970
Now, if we go up here just for a second and hover over here, you can see that this project is stored
40
00:03:06,970 --> 00:03:08,500
in my user home.
41
00:03:08,500 --> 00:03:11,020
PY Charm mac changer.
42
00:03:11,800 --> 00:03:19,210
So I'm going to do see the pie chart projects and by the way you can just press tab as you're typing
43
00:03:19,210 --> 00:03:21,790
a command and it will autocomplete for you.
44
00:03:21,790 --> 00:03:28,720
So all I have to do is type Mac and Tab and as you can see, it automatically auto completes the mac
45
00:03:28,720 --> 00:03:29,410
changer.
46
00:03:30,370 --> 00:03:35,560
Now, if I do, LZ, here to list all the files you can see, I have my mac changer script in here.
47
00:03:36,520 --> 00:03:41,140
And to run this script, as usual, all you have to do is do python mac.
48
00:03:41,140 --> 00:03:44,440
Change your dot py hit enter.
49
00:03:45,790 --> 00:03:47,710
And this didn't show us any errors.
50
00:03:47,710 --> 00:03:48,970
So this is very good.
51
00:03:48,970 --> 00:03:51,370
This means that things did actually work.
52
00:03:51,460 --> 00:03:54,070
And now if we do if config lands zero.
53
00:03:55,950 --> 00:04:04,620
You can see that our Mac address got changed to 001122334466 instead of five five.
54
00:04:04,650 --> 00:04:12,630
So this means that our code in here worked and we managed to execute these three system commands through
55
00:04:12,630 --> 00:04:14,550
our Python script.
56
00:04:15,030 --> 00:04:16,260
Now I know what you're thinking.
57
00:04:16,260 --> 00:04:17,410
This is very simple.
58
00:04:17,430 --> 00:04:20,070
All we're doing is just running system commands.
59
00:04:20,430 --> 00:04:25,710
Doesn't really show the power of Python, but we're still at the very start of the lectures.
60
00:04:25,860 --> 00:04:32,610
I'm actually going to spend a little bit more time on this script to cover a lot of basics about Python
61
00:04:32,610 --> 00:04:33,510
programming.
62
00:04:33,900 --> 00:04:38,730
So in the next lectures, we're going to be building up on this very simple script.
63
00:04:38,730 --> 00:04:46,770
And as we do that, I'm going to teach you conditional statements, variables, regex and more.
64
00:04:46,770 --> 00:04:49,900
And this is the style I'm going to follow throughout the whole course.
65
00:04:49,920 --> 00:04:55,530
We're going to be, first of all, creating a script that does something useful, and then we'll build
66
00:04:55,530 --> 00:04:56,530
up on that.
67
00:04:56,550 --> 00:05:02,400
So this won't be the only script that we create, but we're actually spent some time working and adding
68
00:05:02,400 --> 00:05:09,000
features to this script because as I add features, I want to cover Python basics so that I can teach
69
00:05:09,000 --> 00:05:15,630
you more advanced Python programming in the next sections and build more advanced Python programs.
7022
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.